Zelda Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2023-11-03 10:30:11
Exec Total Coverage
Lines: 1681 4301 39.1%
Functions: 132 334 39.5%
Branches: 932 3048 30.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro5/joystick.h"
5 #include "base/qrs.h"
6 #include "base/dmap.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <math.h>
11 #include <map>
12 #include <filesystem>
13 #include <ctype.h>
14 #include <sstream>
15 #include "base/zc_alleg.h"
16 #include "gamedata.h"
17 #include "zc/zc_init.h"
18 #include "init.h"
19 #include "zc/replay.h"
20 #include "zc/cheats.h"
21 #include "zc/render.h"
22 #include "base/zc_math.h"
23 #include "base/zapp.h"
24 #include "dialog/cheatkeys.h"
25 #include "metadata/metadata.h"
26 #include "zc/zelda.h"
27 #include "zc/saves.h"
28 #include "tiles.h"
29 #include "base/colors.h"
30 #include "pal.h"
31 #include "base/zsys.h"
32 #include "qst.h"
33 #include "zc/zc_sys.h"
34 #include "play_midi.h"
35 #include "gui/jwin_a5.h"
36 #include "base/jwinfsel.h"
37 #include "base/gui.h"
38 #include "midi.h"
39 #include "subscr.h"
40 #include "zc/maps.h"
41 #include "sprite.h"
42 #include "zc/guys.h"
43 #include "zc/hero.h"
44 #include "zc/title.h"
45 #include "particles.h"
46 #include "sound/zcmusic.h"
47 #include "zconsole.h"
48 #include "zc/ffscript.h"
49 #include "dialog/info.h"
50 #include "dialog/alert.h"
51 #include "zc/combos.h"
52 #include "zc/jit.h"
53 #include "zc/zc_subscr.h"
54 #include <fmt/format.h>
55 #include "zinfo.h"
56 #include "base/misctypes.h"
57
58 #ifdef __EMSCRIPTEN__
59 #include "base/emscripten_utils.h"
60 #endif
61
62 using namespace std::chrono_literals;
63
64 extern FFScript FFCore;
65 extern bool Playing;
66 int32_t sfx_voice[WAV_COUNT];
67 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
68 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
69
70 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
71 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
72
73 extern byte monochrome_console;
74
75 extern HeroClass Hero;
76 extern zcmodule moduledata;
77 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
78 extern particle_list particles;
79 extern int32_t loadlast;
80 extern char *sfx_string[WAV_COUNT];
81 byte use_dwm_flush;
82 byte use_save_indicator;
83 int32_t paused_midi_pos = 0;
84 byte midi_suspended = 0;
85 byte zc_192b163_warp_compatibility;
86 char modulepath[2048];
87 bool epilepsyFlashReduction;
88 signed char pause_in_background_menu_init = 0;
89 byte pause_in_background = 0;
90 bool is_sys_pal = false;
91 static bool load_control_called_this_frame;
92 extern PALETTE* hw_palette;
93 extern bool update_hw_pal;
94 extern const char* dmaplist(int32_t index, int32_t* list_size);
95 int32_t getnumber(const char *prompt,int32_t initialval);
96
97 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
98 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
99
100 static const char *qst_module_name = "current_module";
101 #ifdef ALLEGRO_LINUX
102 static const char *samplepath = "samplesoundset/patches.dat";
103 #endif
104 char qst_files_path[2048];
105
106 #ifdef _MSC_VER
107 #define getcwd _getcwd
108 #endif
109
110 bool rF11();
111 bool rI();
112 bool rQ();
113 bool zc_key_pressed();
114
115 #ifdef _WIN32
116
117 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
118 extern "C"
119 {
120 typedef HRESULT(WINAPI *t_DwmFlush)();
121 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
122 }
123
124 void do_DwmFlush()
125 {
126 static HMODULE shell = LoadLibrary("dwmapi.dll");
127
128 if(!shell)
129 return;
130
131 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
132 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
133
134 BOOL enabled;
135 isEnabled(&enabled);
136
137 if(isEnabled)
138 flush();
139 }
140
141 #endif // _WIN32
142
143 83751 bool flash_reduction_enabled(bool check_qr)
144 {
145
4/4
✓ Branch 0 taken 81530 times.
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 81074 times.
✓ Branch 3 taken 83295 times.
83751 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
146 }
147
148 // Dialogue largening
149 void large_dialog(DIALOG *d)
150 {
151 large_dialog(d, 1.5);
152 }
153
154 void large_dialog(DIALOG *d, float RESIZE_AMT)
155 {
156 if(!d[0].d1)
157 {
158 d[0].d1 = 1;
159 int32_t oldwidth = d[0].w;
160 int32_t oldheight = d[0].h;
161 int32_t oldx = d[0].x;
162 int32_t oldy = d[0].y;
163 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
164 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
165 d[0].w = int32_t(d[0].w*RESIZE_AMT);
166 d[0].h = int32_t(d[0].h*RESIZE_AMT);
167
168 for(int32_t i=1; d[i].proc !=NULL; i++)
169 {
170 // Place elements horizontally
171 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
172 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
173
174 if(d[i].proc != d_stringloader)
175 {
176 if(d[i].proc==d_bitmap_proc)
177 {
178 d[i].w *= 2;
179 }
180 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
181 }
182
183 // Place elements vertically
184 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
185 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
186
187 // Vertically resize elements
188 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
189 {
190 d[i].h = int32_t((double)d[i].h*1.5);
191 }
192 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
193 {
194 d[i].y += int32_t((double)d[i].h*0.25);
195 d[i].h = int32_t((double)d[i].h*1.25);
196 }
197 else if(d[i].proc==d_bitmap_proc)
198 {
199 d[i].h *= 2;
200 }
201 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
202
203 // Fix frames
204 if(d[i].proc == jwin_frame_proc)
205 {
206 d[i].x++;
207 d[i].y++;
208 d[i].w-=4;
209 d[i].h-=4;
210 }
211 }
212 }
213
214 for(int32_t i=1; d[i].proc!=NULL; i++)
215 {
216 if(d[i].proc==jwin_slider_proc)
217 continue;
218
219 // Bigger font
220 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
221
222 if(!d[i].dp2 && bigfontproc)
223 {
224 d[i].dp2 = get_zc_font(font_lfont_l);
225 }
226 else if(!bigfontproc)
227 {
228 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
229 }
230
231 // Make checkboxes work
232 if(d[i].proc == jwin_check_proc)
233 d[i].proc = jwin_checkfont_proc;
234 else if(d[i].proc == jwin_radio_proc)
235 d[i].proc = jwin_radiofont_proc;
236 }
237
238 jwin_center_dialog(d);
239 }
240
241
242 /**********************************/
243 /******** System functions ********/
244 /**********************************/
245
246 static char cfg_sect[] = "zeldadx"; //We need to rename this.
247 static char ctrl_sect[] = "Controls";
248 static char sfx_sect[] = "Volume";
249
250 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
251 {
252 return D_O_K;
253 }
254
255 bool is_reserved_key(int c)
256 {
257 switch(c)
258 {
259 case KEY_ESC:
260 return true;
261 }
262 return false;
263 }
264 bool is_reserved_keycombo(int c, int modflag)
265 {
266 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
267 return true;
268 return false;
269 }
270 bool checkcheat(Cheat cheat)
271 {
272 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
273 return true; //Main key pressed
274 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
275 return true; //Alt key pressed
276 return false;
277 }
278 115 void load_default_cheatkeys()
279 {
280 115 memset(cheatkeys, 0, sizeof(cheatkeys));
281 115 cheatkeys[Cheat::Life][0] = KEY_H;
282 115 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
283 115 cheatkeys[Cheat::Magic][0] = KEY_M;
284 115 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
285 115 cheatkeys[Cheat::Rupies][0] = KEY_R;
286 115 cheatkeys[Cheat::Bombs][0] = KEY_B;
287 115 cheatkeys[Cheat::Arrows][0] = KEY_A;
288 115 cheatkeys[Cheat::Clock][0] = KEY_I;
289 115 cheatkeys[Cheat::Walls][0] = KEY_F11;
290 115 cheatkeys[Cheat::Fast][0] = KEY_Q;
291 115 cheatkeys[Cheat::Light][0] = KEY_L;
292 115 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
293 115 cheatkeys[Cheat::Kill][0] = KEY_K;
294 115 cheatkeys[Cheat::GoTo][0] = KEY_G;
295 115 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
296 115 cheatkeys[Cheat::ShowL0][0] = KEY_0;
297 115 cheatkeys[Cheat::ShowL1][0] = KEY_1;
298 115 cheatkeys[Cheat::ShowL2][0] = KEY_2;
299 115 cheatkeys[Cheat::ShowL3][0] = KEY_3;
300 115 cheatkeys[Cheat::ShowL4][0] = KEY_4;
301 115 cheatkeys[Cheat::ShowL5][0] = KEY_5;
302 115 cheatkeys[Cheat::ShowL6][0] = KEY_6;
303 115 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
304 115 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
305 115 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
306 115 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
307 115 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
308 115 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
309 115 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
310 115 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
311 115 }
312 115 void load_game_configs()
313 {
314 115 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"classic.zmod"));
315 115 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
316 115 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
317 115 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
318 115 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
319 115 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
320 115 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
321 115 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
322 115 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
323 115 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
324 115 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
325 115 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
326 115 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
327 115 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
328 115 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
329
330 //cheat modifier keya
331 115 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
332 115 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
333 115 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
334 115 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
335
336 //cheat keys
337 115 load_default_cheatkeys();
338 char buf[256];
339
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 4025 times.
4140 for(size_t q = 1; q < Cheat::Last; ++q)
340 {
341
1/2
✓ Branch 0 taken 4025 times.
✗ Branch 1 not taken.
4025 if(!bindable_cheat((Cheat)q)) continue;
342 4025 std::string cheatname = cheat_to_string((Cheat)q);
343
1/2
✓ Branch 0 taken 4025 times.
✗ Branch 1 not taken.
4025 util::lowerstr(cheatname);
344 4025 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
345
1/2
✓ Branch 0 taken 4025 times.
✗ Branch 1 not taken.
4025 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
346 4025 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
347
1/2
✓ Branch 0 taken 4025 times.
✗ Branch 1 not taken.
4025 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
348 4025 }
349
350
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
351 joystick_index = 0;
352
353 115 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
354 115 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
355 115 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
356 115 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
357 115 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
358 115 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
359 115 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
360 115 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
361 115 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
362 115 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
363
364 115 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
365 115 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
366 115 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
367 115 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
368
369 115 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
370 115 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
371 115 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
372 115 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
373 115 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
374 115 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
375 115 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
376 115 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
377 115 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
378 115 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
379 115 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
380
381 115 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
382 115 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
383 115 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
384 115 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
385
386 115 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
387
388 115 digi_volume = zc_get_config(sfx_sect,"digi",248);
389 115 midi_volume = zc_get_config(sfx_sect,"midi",255);
390 115 sfx_volume = zc_get_config(sfx_sect,"sfx",248);
391 115 emusic_volume = zc_get_config(sfx_sect,"emusic",248);
392 115 pan_style = zc_get_config(sfx_sect,"pan",1);
393 // 1 <= zcmusic_bufsz <= 128
394 115 zcmusic_bufsz = vbound(zc_get_config(sfx_sect,"zcmusic_bufsz",64),1,128);
395 115 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
396 115 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
397 115 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
398 115 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
399 115 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
400 115 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
401 115 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
402 #ifdef __EMSCRIPTEN__
403 if (em_is_mobile()) NameEntryMode = 2;
404 #endif
405 115 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
406 115 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
407 115 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
408 115 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
409 115 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
410
411 115 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
412 115 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
413 115 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
414 115 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
415 115 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
416 115 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
417 115 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
418
419 115 loadlast = zc_get_config(cfg_sect,"load_last",0);
420
421 115 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
422
423 115 zc_color_depth = (byte) zc_get_config(cfg_sect,"color_depth",8);
424
425 115 forceExit = (byte) zc_get_config(cfg_sect,"force_exit",0);
426 115 info_opacity = zc_get_config("zc","debug_info_opacity",255);
427 #ifdef _WIN32
428 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
429 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
430 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
431 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
432
433 // This one's for Aero
434 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
435
436 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
437 #else //UNIX
438 115 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
439 115 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
440 115 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
441 #endif
442 115 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
443 115 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
444
445 115 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
446 115 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
447 115 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
448 115 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
449 115 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
450 115 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
451 115 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
452 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
453 115 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
454 115 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
455 115 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
456 115 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
457 115 }
458
459 void save_control_configs(bool kb)
460 {
461 if(kb)
462 {
463 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
464 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
465 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
466 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
467
468 if (!replay_is_replaying())
469 {
470 zc_set_config(ctrl_sect,"key_a",Akey);
471 zc_set_config(ctrl_sect,"key_b",Bkey);
472 zc_set_config(ctrl_sect,"key_s",Skey);
473 zc_set_config(ctrl_sect,"key_l",Lkey);
474 zc_set_config(ctrl_sect,"key_r",Rkey);
475 zc_set_config(ctrl_sect,"key_p",Pkey);
476 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
477 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
478 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
479 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
480 zc_set_config(ctrl_sect,"key_up", DUkey);
481 zc_set_config(ctrl_sect,"key_down", DDkey);
482 zc_set_config(ctrl_sect,"key_left", DLkey);
483 zc_set_config(ctrl_sect,"key_right",DRkey);
484 }
485 }
486 else
487 {
488 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
489 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
490 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
491 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
492 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
493 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
494 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
495 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
496 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
497 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
498 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
499 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
500 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
501 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
502
503 zc_set_config(ctrl_sect,"btn_a",Abtn);
504 zc_set_config(ctrl_sect,"btn_b",Bbtn);
505 zc_set_config(ctrl_sect,"btn_s",Sbtn);
506 zc_set_config(ctrl_sect,"btn_m",Mbtn);
507 zc_set_config(ctrl_sect,"btn_l",Lbtn);
508 zc_set_config(ctrl_sect,"btn_r",Rbtn);
509 zc_set_config(ctrl_sect,"btn_p",Pbtn);
510 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
511 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
512 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
513 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
514
515 zc_set_config(ctrl_sect,"btn_up",DUbtn);
516 zc_set_config(ctrl_sect,"btn_down",DDbtn);
517 zc_set_config(ctrl_sect,"btn_left",DLbtn);
518 zc_set_config(ctrl_sect,"btn_right",DRbtn);
519 }
520 }
521
522 void save_cheatkeys()
523 {
524 char buf[256];
525 for(size_t q = 1; q < Cheat::Last; ++q)
526 {
527 if(!bindable_cheat((Cheat)q)) continue;
528 std::string cheatname = cheat_to_string((Cheat)q);
529 util::lowerstr(cheatname);
530 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
531 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
532 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
533 if(cheatkeys[q][1])
534 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
535 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
536 }
537 }
538
539 void save_game_configs()
540 {
541 packfile_password("");
542
543 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
544
545 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
546 {
547 int o_window_x, o_window_y;
548 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
549 zc_set_config(cfg_sect,"window_x",o_window_x);
550 zc_set_config(cfg_sect,"window_y",o_window_y);
551 }
552
553 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
554 {
555 window_width = al_get_display_width(all_get_display());
556 window_height = al_get_display_height(all_get_display());
557 zc_set_config(cfg_sect,"window_width",window_width);
558 zc_set_config(cfg_sect,"window_height",window_height);
559 }
560
561 zc_set_config(cfg_sect,"load_last",loadlast);
562 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
563
564 flush_config_file();
565 #ifdef __EMSCRIPTEN__
566 em_sync_fs();
567 #endif
568 }
569
570 //----------------------------------------------------------------
571
572 // Timers
573
574 23834 void fps_callback()
575 {
576 23834 lastfps=framecnt;
577 23834 framecnt=0;
578 23834 }
579
580 END_OF_FUNCTION(fps_callback)
581
582 115 int32_t Z_init_timers()
583 {
584 static bool didit = false;
585 const static char *err_str = "Couldn't allocate timer";
586 115 err_str = err_str; //Unused variable warning
587
588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if(didit)
589 return 1;
590
591 115 didit = true;
592
593 LOCK_VARIABLE(lastfps);
594 LOCK_VARIABLE(framecnt);
595 LOCK_FUNCTION(fps_callback);
596
597
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
598 return 0;
599
600 115 return 1;
601 115 }
602
603 void Z_remove_timers()
604 {
605 remove_int(fps_callback);
606 }
607
608 //----------------------------------------------------------------
609
610 void go()
611 {
612 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
613 }
614
615 void comeback()
616 {
617 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
618 }
619
620 void dump_pal(BITMAP *dest)
621 {
622 for(int32_t i=0; i<256; i++)
623 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
624 }
625
626 //----------------------------------------------------------------
627
628 int game_mouse_index = ZCM_BLANK;
629 static bool system_mouse = false;
630 28 bool sys_mouse()
631 {
632 28 system_mouse = true;
633 28 return MouseSprite::set(ZCM_NORMAL);
634 }
635 557 bool game_mouse()
636 {
637 557 system_mouse = false;
638 557 return MouseSprite::set(game_mouse_index);
639 }
640 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
641 {
642 if(!bmp)
643 return;
644 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
645 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
646 if(bmp->w == scaledw && bmp->h == scaledh)
647 user_scale = false;
648 if(user_scale || sys_recolor)
649 {
650 if(!user_scale) scale = 1;
651 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
652 if(user_scale)
653 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
654 else
655 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
656 if(sys_recolor)
657 recolor_mouse(tmpbmp);
658 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
659 destroy_bitmap(tmpbmp);
660 }
661 else
662 {
663 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
664 }
665 }
666
667 //Handles converting the mouse sprite from the .dat file
668 void recolor_mouse(BITMAP* bmp)
669 {
670 for(int32_t x = 0; x < bmp->w; ++x)
671 {
672 for(int32_t y = 0; y < bmp->h; ++y)
673 {
674 int32_t color = getpixel(bmp, x, y);
675 switch(color)
676 {
677 case dvc(1):
678 color = jwin_pal[jcCURSORMISC];
679 break;
680 case dvc(2):
681 color = jwin_pal[jcCURSOROUTLINE];
682 break;
683 case dvc(3):
684 color = jwin_pal[jcCURSORLIGHT];
685 break;
686 case dvc(5):
687 color = jwin_pal[jcCURSORDARK];
688 break;
689 default:
690 continue;
691 }
692 putpixel(bmp, x, y, color);
693 }
694 }
695 }
696 void load_mouse()
697 {
698 PALETTE pal;
699 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
700 if (!cursor_bitmap)
701 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
702
703 enter_sys_pal();
704 MouseSprite::set(-1);
705 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
706 int32_t sz = 16*scale;
707 for(int32_t j = 0; j < 1; ++j)
708 {
709 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
710 if(zcmouse[j])
711 destroy_bitmap(zcmouse[j]);
712 zcmouse[j] = create_bitmap_ex(8,sz,sz);
713 clear_bitmap(zcmouse[j]);
714 clear_bitmap(tmpbmp);
715 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
716 recolor_mouse(tmpbmp);
717 if(sz!=16)
718 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
719 else
720 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
721 destroy_bitmap(tmpbmp);
722 }
723 if(!hw_palette) hw_palette = &RAMpal;
724 zc_set_palette(*hw_palette);
725
726 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
727 clear_bitmap(blankmouse);
728
729 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
730 MouseSprite::assign(ZCM_BLANK, blankmouse);
731 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
732
733 //Reload the mouse
734 if(system_mouse)
735 sys_mouse();
736 else game_mouse();
737
738 destroy_bitmap(blankmouse);
739 destroy_bitmap(cursor_bitmap);
740 exit_sys_pal();
741 }
742
743 // sets the video mode and initializes the palette and mouse sprite
744 115 bool game_vid_mode(int32_t mode,int32_t wait)
745 {
746
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if (is_headless())
747 115 return true;
748
749 extern int zq_screen_w, zq_screen_h;
750 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
751 {
752 return false;
753 }
754
755 scrx = (resx-320)>>1;
756 scry = (resy-240)>>1;
757 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
758 zcmouse[q] = NULL;
759 load_mouse();
760
761 for(int32_t i=240; i<256; i++)
762 RAMpal[i]=pal_gui[i];
763
764 zc_set_palette(RAMpal);
765 clear_to_color(screen,BLACK);
766
767 rest(wait);
768 return true;
769 115 }
770
771 8 void null_quest()
772 {
773 char qstdat_string[2048];
774 8 strcpy(qstdat_string, "modules/classic/default.qst");
775
776 #ifdef __EMSCRIPTEN__
777 // The quest template data file is not included because it's really big and isn't really needed
778 // for the player, except to initialize some graphics. Those same graphics exist in this quest file,
779 // which is much smaller.
780 strcpy(qstdat_string, "modules/classic/title_gfx.dat");
781 #endif
782
783 8 byte skip_flags[4] = { 0 };
784
785 8 loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
786 8 }
787
788 8 void init_NES_mode()
789 {
790 8 null_quest();
791 8 }
792
793 //----------------------------------------------------------------
794
795 qword trianglelines[16]=
796 {
797 0x0000000000000000ULL,
798 0xFD00000000000000ULL,
799 0xFDFD000000000000ULL,
800 0xFDFDFD0000000000ULL,
801 0xFDFDFDFD00000000ULL,
802 0xFDFDFDFDFD000000ULL,
803 0xFDFDFDFDFDFD0000ULL,
804 0xFDFDFDFDFDFDFD00ULL,
805 0xFDFDFDFDFDFDFDFDULL,
806 0x00FDFDFDFDFDFDFDULL,
807 0x0000FDFDFDFDFDFDULL,
808 0x000000FDFDFDFDFDULL,
809 0x00000000FDFDFDFDULL,
810 0x0000000000FDFDFDULL,
811 0x000000000000FDFDULL,
812 0x00000000000000FDULL,
813 };
814
815 word screen_triangles[28][32];
816 /*
817 qword triangles[4][16]= //[direction][value]
818 {
819 {
820 0x00000000, 0x10000000, 0x21000000, 0x32100000, 0x43210000, 0x54321000, 0x65432100, 0x76543210, 0x87654321, 0x88765432, 0x88876543, 0x88887654, 0x88888765, 0x88888876, 0x88888887, 0x88888888
821 },
822 {
823 0x00000000, 0xF0000000, 0xEF000000, 0xFDF00000, 0xCFDF0000, 0xBCFDF000, 0xABCFDF00, 0x9ABCFDF0, 0x89ABCFDF, 0x889ABCFD, 0x8889ABCD, 0x88889ABC, 0x888889AB, 0x8888889A, 0x88888889, 0x88888888
824 },
825 {
826 0x00000000, 0x00000001, 0x00000012, 0x00000123, 0x00001234, 0x00012345, 0x00123456, 0x01234567, 0x12345678, 0x23456788, 0x34567888, 0x45678888, 0x56788888, 0x67888888, 0x78888888, 0x88888888
827 },
828 {
829 0x00000000, 0x0000000F, 0x000000FE, 0x00000FED, 0x0000FEDC, 0x000FEDCB, 0x00FEDCBA, 0x0FEDCBA9, 0xFEDCBA98, 0xEDCBA988, 0xDCBA9888, 0xCBA98888, 0xBA988888, 0xA9888888, 0x98888888, 0x88888888
830 }
831 };
832 */
833
834
835 /*
836 byte triangles[4][16][8]= //[direction][value][line]
837 {
838 {
839 {
840 0, 0, 0, 0, 0, 0, 0, 0
841 },
842 {
843 1, 0, 0, 0, 0, 0, 0, 0
844 },
845 {
846 2, 1, 0, 0, 0, 0, 0, 0
847 },
848 {
849 3, 2, 1, 0, 0, 0, 0, 0
850 },
851 {
852 4, 3, 2, 1, 0, 0, 0, 0
853 },
854 {
855 5, 4, 3, 2, 1, 0, 0, 0
856 },
857 {
858 6, 5, 4, 3, 2, 1, 0, 0
859 },
860 {
861 7, 6, 5, 4, 3, 2, 1, 0
862 },
863 {
864 8, 7, 6, 5, 4, 3, 2, 1
865 },
866 {
867 8, 8, 7, 6, 5, 4, 3, 2
868 },
869 {
870 8, 8, 8, 7, 6, 5, 4, 3
871 },
872 {
873 8, 8, 8, 8, 7, 6, 5, 4
874 },
875 {
876 8, 8, 8, 8, 8, 7, 6, 5
877 },
878 {
879 8, 8, 8, 8, 8, 8, 7, 6
880 },
881 {
882 8, 8, 8, 8, 8, 8, 8, 7
883 },
884 {
885 8, 8, 8, 8, 8, 8, 8, 8
886 }
887 },
888 {
889 {
890 0, 0, 0, 0, 0, 0, 0, 0
891 },
892 {
893 15, 0, 0, 0, 0, 0, 0, 0
894 },
895 {
896 14, 15, 0, 0, 0, 0, 0, 0
897 },
898 {
899 13, 14, 15, 0, 0, 0, 0, 0
900 },
901 {
902 12, 13, 14, 15, 0, 0, 0, 0
903 },
904 {
905 11, 12, 13, 14, 15, 0, 0, 0
906 },
907 {
908 10, 11, 12, 13, 14, 15, 0, 0
909 },
910 {
911 9, 10, 11, 12, 13, 14, 15, 0
912 },
913 {
914 8, 9, 10, 11, 12, 13, 14, 15
915 },
916 {
917 8, 8, 9, 10, 11, 12, 13, 14
918 },
919 {
920 8, 8, 8, 9, 10, 11, 12, 13
921 },
922 {
923 8, 8, 8, 8, 9, 10, 11, 12
924 },
925 {
926 8, 8, 8, 8, 8, 9, 10, 11
927 },
928 {
929 8, 8, 8, 8, 8, 8, 9, 10
930 },
931 {
932 8, 8, 8, 8, 8, 8, 8, 9
933 },
934 {
935 8, 8, 8, 8, 8, 8, 8, 8
936 }
937 },
938 {
939 {
940 0, 0, 0, 0, 0, 0, 0, 0
941 },
942 {
943 0, 0, 0, 0, 0, 0, 0, 1
944 },
945 {
946 0, 0, 0, 0, 0, 0, 1, 2
947 },
948 {
949 0, 0, 0, 0, 0, 1, 2, 3
950 },
951 {
952 0, 0, 0, 0, 1, 2, 3, 4
953 },
954 {
955 0, 0, 0, 1, 2, 3, 4, 5
956 },
957 {
958 0, 0, 1, 2, 3, 4, 5, 6
959 },
960 {
961 0, 1, 2, 3, 4, 5, 6, 7
962 },
963 {
964 1, 2, 3, 4, 5, 6, 7, 8
965 },
966 {
967 2, 3, 4, 5, 6, 7, 8, 8
968 },
969 {
970 3, 4, 5, 6, 7, 8, 8, 8
971 },
972 {
973 4, 5, 6, 7, 8, 8, 8, 8
974 },
975 {
976 5, 6, 7, 8, 8, 8, 8, 8
977 },
978 {
979 6, 7, 8, 8, 8, 8, 8, 8
980 },
981 {
982 7, 8, 8, 8, 8, 8, 8, 8
983 },
984 {
985 8, 8, 8, 8, 8, 8, 8, 8
986 }
987 },
988 {
989 {
990 0, 0, 0, 0, 0, 0, 0, 0
991 },
992 {
993 0, 0, 0, 0, 0, 0, 0, 15
994 },
995 {
996 0, 0, 0, 0, 0, 0, 15, 14
997 },
998 {
999 0, 0, 0, 0, 0, 15, 14, 13
1000 },
1001 {
1002 0, 0, 0, 0, 15, 14, 13, 12
1003 },
1004 {
1005 0, 0, 0, 15, 14, 13, 12, 11
1006 },
1007 {
1008 0, 0, 15, 14, 13, 12, 11, 10
1009 },
1010 {
1011 0, 15, 14, 13, 12, 11, 10, 9
1012 },
1013 {
1014 15, 14, 13, 12, 11, 10, 9, 8
1015 },
1016 {
1017 14, 13, 12, 11, 10, 9, 8, 8
1018 },
1019 {
1020 13, 12, 11, 10, 9, 8, 8, 8
1021 },
1022 {
1023 12, 11, 10, 9, 8, 8, 8, 8
1024 },
1025 {
1026 11, 10, 9, 8, 8, 8, 8, 8
1027 },
1028 {
1029 10, 9, 8, 8, 8, 8, 8, 8
1030 },
1031 {
1032 9, 8, 8, 8, 8, 8, 8, 8
1033 },
1034 {
1035 8, 8, 8, 8, 8, 8, 8, 8
1036 }
1037 }
1038 };
1039 */
1040
1041
1042
1043 /*
1044 for (int32_t blockrow=0; blockrow<30; ++i)
1045 {
1046 for (int32_t linerow=0; linerow<8; ++i)
1047 {
1048 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1049 for (int32_t blockcolumn=0; blockcolumn<40; ++i)
1050 {
1051 triangleline=triangles[0][screen_triangles[blockrow][blockcolumn]][linerow];
1052 ++triangleline;
1053 }
1054 }
1055 }
1056 */
1057
1058 // the ULL suffixes are to prevent this warning:
1059 // warning: integer constant is too large for "int32_t" type
1060
1061 qword triangles[4][16][8]= //[direction][value][line]
1062 {
1063 {
1064 {
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL,
1071 0x0000000000000000ULL,
1072 0x0000000000000000ULL
1073 },
1074 {
1075 0xFD00000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL,
1081 0x0000000000000000ULL,
1082 0x0000000000000000ULL
1083 },
1084 {
1085 0xFDFD000000000000ULL,
1086 0xFD00000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL,
1091 0x0000000000000000ULL,
1092 0x0000000000000000ULL
1093 },
1094 {
1095 0xFDFDFD0000000000ULL,
1096 0xFDFD000000000000ULL,
1097 0xFD00000000000000ULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL,
1101 0x0000000000000000ULL,
1102 0x0000000000000000ULL
1103 },
1104 {
1105 0xFDFDFDFD00000000ULL,
1106 0xFDFDFD0000000000ULL,
1107 0xFDFD000000000000ULL,
1108 0xFD00000000000000ULL,
1109 0x0000000000000000ULL,
1110 0x0000000000000000ULL,
1111 0x0000000000000000ULL,
1112 0x0000000000000000ULL
1113 },
1114 {
1115 0xFDFDFDFDFD000000ULL,
1116 0xFDFDFDFD00000000ULL,
1117 0xFDFDFD0000000000ULL,
1118 0xFDFD000000000000ULL,
1119 0xFD00000000000000ULL,
1120 0x0000000000000000ULL,
1121 0x0000000000000000ULL,
1122 0x0000000000000000ULL
1123 },
1124 {
1125 0xFDFDFDFDFDFD0000ULL,
1126 0xFDFDFDFDFD000000ULL,
1127 0xFDFDFDFD00000000ULL,
1128 0xFDFDFD0000000000ULL,
1129 0xFDFD000000000000ULL,
1130 0xFD00000000000000ULL,
1131 0x0000000000000000ULL,
1132 0x0000000000000000ULL
1133 },
1134 {
1135 0xFDFDFDFDFDFDFD00ULL,
1136 0xFDFDFDFDFDFD0000ULL,
1137 0xFDFDFDFDFD000000ULL,
1138 0xFDFDFDFD00000000ULL,
1139 0xFDFDFD0000000000ULL,
1140 0xFDFD000000000000ULL,
1141 0xFD00000000000000ULL,
1142 0x0000000000000000ULL
1143 },
1144 {
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0xFDFDFDFDFDFDFD00ULL,
1147 0xFDFDFDFDFDFD0000ULL,
1148 0xFDFDFDFDFD000000ULL,
1149 0xFDFDFDFD00000000ULL,
1150 0xFDFDFD0000000000ULL,
1151 0xFDFD000000000000ULL,
1152 0xFD00000000000000ULL
1153 },
1154 {
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFD00ULL,
1158 0xFDFDFDFDFDFD0000ULL,
1159 0xFDFDFDFDFD000000ULL,
1160 0xFDFDFDFD00000000ULL,
1161 0xFDFDFD0000000000ULL,
1162 0xFDFD000000000000ULL
1163 },
1164 {
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFD00ULL,
1169 0xFDFDFDFDFDFD0000ULL,
1170 0xFDFDFDFDFD000000ULL,
1171 0xFDFDFDFD00000000ULL,
1172 0xFDFDFD0000000000ULL
1173 },
1174 {
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFD00ULL,
1180 0xFDFDFDFDFDFD0000ULL,
1181 0xFDFDFDFDFD000000ULL,
1182 0xFDFDFDFD00000000ULL
1183 },
1184 {
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFD00ULL,
1191 0xFDFDFDFDFDFD0000ULL,
1192 0xFDFDFDFDFD000000ULL
1193 },
1194 {
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL,
1201 0xFDFDFDFDFDFDFD00ULL,
1202 0xFDFDFDFDFDFD0000ULL
1203 },
1204 {
1205 0xFDFDFDFDFDFDFDFDULL,
1206 0xFDFDFDFDFDFDFDFDULL,
1207 0xFDFDFDFDFDFDFDFDULL,
1208 0xFDFDFDFDFDFDFDFDULL,
1209 0xFDFDFDFDFDFDFDFDULL,
1210 0xFDFDFDFDFDFDFDFDULL,
1211 0xFDFDFDFDFDFDFDFDULL,
1212 0xFDFDFDFDFDFDFD00ULL
1213 },
1214 {
1215 0xFDFDFDFDFDFDFDFDULL,
1216 0xFDFDFDFDFDFDFDFDULL,
1217 0xFDFDFDFDFDFDFDFDULL,
1218 0xFDFDFDFDFDFDFDFDULL,
1219 0xFDFDFDFDFDFDFDFDULL,
1220 0xFDFDFDFDFDFDFDFDULL,
1221 0xFDFDFDFDFDFDFDFDULL,
1222 0xFDFDFDFDFDFDFDFDULL
1223 }
1224 },
1225 {
1226 {
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL
1235 },
1236 {
1237 0x00000000000000FDULL,
1238 0x0000000000000000ULL,
1239 0x0000000000000000ULL,
1240 0x0000000000000000ULL,
1241 0x0000000000000000ULL,
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL
1245 },
1246 {
1247 0x000000000000FDFDULL,
1248 0x00000000000000FDULL,
1249 0x0000000000000000ULL,
1250 0x0000000000000000ULL,
1251 0x0000000000000000ULL,
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL
1255 },
1256 {
1257 0x0000000000FDFDFDULL,
1258 0x000000000000FDFDULL,
1259 0x00000000000000FDULL,
1260 0x0000000000000000ULL,
1261 0x0000000000000000ULL,
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0x0000000000000000ULL
1265 },
1266 {
1267 0x00000000FDFDFDFDULL,
1268 0x0000000000FDFDFDULL,
1269 0x000000000000FDFDULL,
1270 0x00000000000000FDULL,
1271 0x0000000000000000ULL,
1272 0x0000000000000000ULL,
1273 0x0000000000000000ULL,
1274 0x0000000000000000ULL
1275 },
1276 {
1277 0x000000FDFDFDFDFDULL,
1278 0x00000000FDFDFDFDULL,
1279 0x0000000000FDFDFDULL,
1280 0x000000000000FDFDULL,
1281 0x00000000000000FDULL,
1282 0x0000000000000000ULL,
1283 0x0000000000000000ULL,
1284 0x0000000000000000ULL
1285 },
1286 {
1287 0x0000FDFDFDFDFDFDULL,
1288 0x000000FDFDFDFDFDULL,
1289 0x00000000FDFDFDFDULL,
1290 0x0000000000FDFDFDULL,
1291 0x000000000000FDFDULL,
1292 0x00000000000000FDULL,
1293 0x0000000000000000ULL,
1294 0x0000000000000000ULL
1295 },
1296 {
1297 0x00FDFDFDFDFDFDFDULL,
1298 0x0000FDFDFDFDFDFDULL,
1299 0x000000FDFDFDFDFDULL,
1300 0x00000000FDFDFDFDULL,
1301 0x0000000000FDFDFDULL,
1302 0x000000000000FDFDULL,
1303 0x00000000000000FDULL,
1304 0x0000000000000000ULL
1305 },
1306 {
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0x00FDFDFDFDFDFDFDULL,
1309 0x0000FDFDFDFDFDFDULL,
1310 0x000000FDFDFDFDFDULL,
1311 0x00000000FDFDFDFDULL,
1312 0x0000000000FDFDFDULL,
1313 0x000000000000FDFDULL,
1314 0x00000000000000FDULL
1315 },
1316 {
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0x00FDFDFDFDFDFDFDULL,
1320 0x0000FDFDFDFDFDFDULL,
1321 0x000000FDFDFDFDFDULL,
1322 0x00000000FDFDFDFDULL,
1323 0x0000000000FDFDFDULL,
1324 0x000000000000FDFDULL
1325 },
1326 {
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0x00FDFDFDFDFDFDFDULL,
1331 0x0000FDFDFDFDFDFDULL,
1332 0x000000FDFDFDFDFDULL,
1333 0x00000000FDFDFDFDULL,
1334 0x0000000000FDFDFDULL
1335 },
1336 {
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0x00FDFDFDFDFDFDFDULL,
1342 0x0000FDFDFDFDFDFDULL,
1343 0x000000FDFDFDFDFDULL,
1344 0x00000000FDFDFDFDULL
1345 },
1346 {
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0x00FDFDFDFDFDFDFDULL,
1353 0x0000FDFDFDFDFDFDULL,
1354 0x000000FDFDFDFDFDULL
1355 },
1356 {
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL,
1363 0x00FDFDFDFDFDFDFDULL,
1364 0x0000FDFDFDFDFDFDULL
1365 },
1366 {
1367 0xFDFDFDFDFDFDFDFDULL,
1368 0xFDFDFDFDFDFDFDFDULL,
1369 0xFDFDFDFDFDFDFDFDULL,
1370 0xFDFDFDFDFDFDFDFDULL,
1371 0xFDFDFDFDFDFDFDFDULL,
1372 0xFDFDFDFDFDFDFDFDULL,
1373 0xFDFDFDFDFDFDFDFDULL,
1374 0x00FDFDFDFDFDFDFDULL
1375 },
1376 {
1377 0xFDFDFDFDFDFDFDFDULL,
1378 0xFDFDFDFDFDFDFDFDULL,
1379 0xFDFDFDFDFDFDFDFDULL,
1380 0xFDFDFDFDFDFDFDFDULL,
1381 0xFDFDFDFDFDFDFDFDULL,
1382 0xFDFDFDFDFDFDFDFDULL,
1383 0xFDFDFDFDFDFDFDFDULL,
1384 0xFDFDFDFDFDFDFDFDULL
1385 }
1386 },
1387 {
1388 {
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL
1397 },
1398 {
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x0000000000000000ULL,
1403 0x0000000000000000ULL,
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0xFD00000000000000ULL
1407 },
1408 {
1409 0x0000000000000000ULL,
1410 0x0000000000000000ULL,
1411 0x0000000000000000ULL,
1412 0x0000000000000000ULL,
1413 0x0000000000000000ULL,
1414 0x0000000000000000ULL,
1415 0xFD00000000000000ULL,
1416 0xFDFD000000000000ULL
1417 },
1418 {
1419 0x0000000000000000ULL,
1420 0x0000000000000000ULL,
1421 0x0000000000000000ULL,
1422 0x0000000000000000ULL,
1423 0x0000000000000000ULL,
1424 0xFD00000000000000ULL,
1425 0xFDFD000000000000ULL,
1426 0xFDFDFD0000000000ULL
1427 },
1428 {
1429 0x0000000000000000ULL,
1430 0x0000000000000000ULL,
1431 0x0000000000000000ULL,
1432 0x0000000000000000ULL,
1433 0xFD00000000000000ULL,
1434 0xFDFD000000000000ULL,
1435 0xFDFDFD0000000000ULL,
1436 0xFDFDFDFD00000000ULL
1437 },
1438 {
1439 0x0000000000000000ULL,
1440 0x0000000000000000ULL,
1441 0x0000000000000000ULL,
1442 0xFD00000000000000ULL,
1443 0xFDFD000000000000ULL,
1444 0xFDFDFD0000000000ULL,
1445 0xFDFDFDFD00000000ULL,
1446 0xFDFDFDFDFD000000ULL
1447 },
1448 {
1449 0x0000000000000000ULL,
1450 0x0000000000000000ULL,
1451 0xFD00000000000000ULL,
1452 0xFDFD000000000000ULL,
1453 0xFDFDFD0000000000ULL,
1454 0xFDFDFDFD00000000ULL,
1455 0xFDFDFDFDFD000000ULL,
1456 0xFDFDFDFDFDFD0000ULL
1457 },
1458 {
1459 0x0000000000000000ULL,
1460 0xFD00000000000000ULL,
1461 0xFDFD000000000000ULL,
1462 0xFDFDFD0000000000ULL,
1463 0xFDFDFDFD00000000ULL,
1464 0xFDFDFDFDFD000000ULL,
1465 0xFDFDFDFDFDFD0000ULL,
1466 0xFDFDFDFDFDFDFD00ULL
1467 },
1468 {
1469 0xFD00000000000000ULL,
1470 0xFDFD000000000000ULL,
1471 0xFDFDFD0000000000ULL,
1472 0xFDFDFDFD00000000ULL,
1473 0xFDFDFDFDFD000000ULL,
1474 0xFDFDFDFDFDFD0000ULL,
1475 0xFDFDFDFDFDFDFD00ULL,
1476 0xFDFDFDFDFDFDFDFDULL
1477 },
1478 {
1479 0xFDFD000000000000ULL,
1480 0xFDFDFD0000000000ULL,
1481 0xFDFDFDFD00000000ULL,
1482 0xFDFDFDFDFD000000ULL,
1483 0xFDFDFDFDFDFD0000ULL,
1484 0xFDFDFDFDFDFDFD00ULL,
1485 0xFDFDFDFDFDFDFDFDULL,
1486 0xFDFDFDFDFDFDFDFDULL
1487 },
1488 {
1489 0xFDFDFD0000000000ULL,
1490 0xFDFDFDFD00000000ULL,
1491 0xFDFDFDFDFD000000ULL,
1492 0xFDFDFDFDFDFD0000ULL,
1493 0xFDFDFDFDFDFDFD00ULL,
1494 0xFDFDFDFDFDFDFDFDULL,
1495 0xFDFDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL
1497 },
1498 {
1499 0xFDFDFDFD00000000ULL,
1500 0xFDFDFDFDFD000000ULL,
1501 0xFDFDFDFDFDFD0000ULL,
1502 0xFDFDFDFDFDFDFD00ULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL
1507 },
1508 {
1509 0xFDFDFDFDFD000000ULL,
1510 0xFDFDFDFDFDFD0000ULL,
1511 0xFDFDFDFDFDFDFD00ULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL
1517 },
1518 {
1519 0xFDFDFDFDFDFD0000ULL,
1520 0xFDFDFDFDFDFDFD00ULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL,
1525 0xFDFDFDFDFDFDFDFDULL,
1526 0xFDFDFDFDFDFDFDFDULL
1527 },
1528 {
1529 0xFDFDFDFDFDFDFD00ULL,
1530 0xFDFDFDFDFDFDFDFDULL,
1531 0xFDFDFDFDFDFDFDFDULL,
1532 0xFDFDFDFDFDFDFDFDULL,
1533 0xFDFDFDFDFDFDFDFDULL,
1534 0xFDFDFDFDFDFDFDFDULL,
1535 0xFDFDFDFDFDFDFDFDULL,
1536 0xFDFDFDFDFDFDFDFDULL
1537 },
1538 {
1539 0xFDFDFDFDFDFDFDFDULL,
1540 0xFDFDFDFDFDFDFDFDULL,
1541 0xFDFDFDFDFDFDFDFDULL,
1542 0xFDFDFDFDFDFDFDFDULL,
1543 0xFDFDFDFDFDFDFDFDULL,
1544 0xFDFDFDFDFDFDFDFDULL,
1545 0xFDFDFDFDFDFDFDFDULL,
1546 0xFDFDFDFDFDFDFDFDULL
1547 }
1548 },
1549 {
1550 {
1551 0x0000000000000000ULL,
1552 0x0000000000000000ULL,
1553 0x0000000000000000ULL,
1554 0x0000000000000000ULL,
1555 0x0000000000000000ULL,
1556 0x0000000000000000ULL,
1557 0x0000000000000000ULL,
1558 0x0000000000000000ULL
1559 },
1560 {
1561 0x0000000000000000ULL,
1562 0x0000000000000000ULL,
1563 0x0000000000000000ULL,
1564 0x0000000000000000ULL,
1565 0x0000000000000000ULL,
1566 0x0000000000000000ULL,
1567 0x0000000000000000ULL,
1568 0x00000000000000FDULL
1569 },
1570 {
1571 0x0000000000000000ULL,
1572 0x0000000000000000ULL,
1573 0x0000000000000000ULL,
1574 0x0000000000000000ULL,
1575 0x0000000000000000ULL,
1576 0x0000000000000000ULL,
1577 0x00000000000000FDULL,
1578 0x000000000000FDFDULL
1579 },
1580 {
1581 0x0000000000000000ULL,
1582 0x0000000000000000ULL,
1583 0x0000000000000000ULL,
1584 0x0000000000000000ULL,
1585 0x0000000000000000ULL,
1586 0x00000000000000FDULL,
1587 0x000000000000FDFDULL,
1588 0x0000000000FDFDFDULL
1589 },
1590 {
1591 0x0000000000000000ULL,
1592 0x0000000000000000ULL,
1593 0x0000000000000000ULL,
1594 0x0000000000000000ULL,
1595 0x00000000000000FDULL,
1596 0x000000000000FDFDULL,
1597 0x0000000000FDFDFDULL,
1598 0x00000000FDFDFDFDULL
1599 },
1600 {
1601 0x0000000000000000ULL,
1602 0x0000000000000000ULL,
1603 0x0000000000000000ULL,
1604 0x00000000000000FDULL,
1605 0x000000000000FDFDULL,
1606 0x0000000000FDFDFDULL,
1607 0x00000000FDFDFDFDULL,
1608 0x000000FDFDFDFDFDULL
1609 },
1610 {
1611 0x0000000000000000ULL,
1612 0x0000000000000000ULL,
1613 0x00000000000000FDULL,
1614 0x000000000000FDFDULL,
1615 0x0000000000FDFDFDULL,
1616 0x00000000FDFDFDFDULL,
1617 0x000000FDFDFDFDFDULL,
1618 0x0000FDFDFDFDFDFDULL
1619 },
1620 {
1621 0x0000000000000000ULL,
1622 0x00000000000000FDULL,
1623 0x000000000000FDFDULL,
1624 0x0000000000FDFDFDULL,
1625 0x00000000FDFDFDFDULL,
1626 0x000000FDFDFDFDFDULL,
1627 0x0000FDFDFDFDFDFDULL,
1628 0x00FDFDFDFDFDFDFDULL
1629 },
1630 {
1631 0x00000000000000FDULL,
1632 0x000000000000FDFDULL,
1633 0x0000000000FDFDFDULL,
1634 0x00000000FDFDFDFDULL,
1635 0x000000FDFDFDFDFDULL,
1636 0x0000FDFDFDFDFDFDULL,
1637 0x00FDFDFDFDFDFDFDULL,
1638 0xFDFDFDFDFDFDFDFDULL
1639 },
1640 {
1641 0x000000000000FDFDULL,
1642 0x0000000000FDFDFDULL,
1643 0x00000000FDFDFDFDULL,
1644 0x000000FDFDFDFDFDULL,
1645 0x0000FDFDFDFDFDFDULL,
1646 0x00FDFDFDFDFDFDFDULL,
1647 0xFDFDFDFDFDFDFDFDULL,
1648 0xFDFDFDFDFDFDFDFDULL
1649 },
1650 {
1651 0x0000000000FDFDFDULL,
1652 0x00000000FDFDFDFDULL,
1653 0x000000FDFDFDFDFDULL,
1654 0x0000FDFDFDFDFDFDULL,
1655 0x00FDFDFDFDFDFDFDULL,
1656 0xFDFDFDFDFDFDFDFDULL,
1657 0xFDFDFDFDFDFDFDFDULL,
1658 0xFDFDFDFDFDFDFDFDULL
1659 },
1660 {
1661 0x00000000FDFDFDFDULL,
1662 0x000000FDFDFDFDFDULL,
1663 0x0000FDFDFDFDFDFDULL,
1664 0x00FDFDFDFDFDFDFDULL,
1665 0xFDFDFDFDFDFDFDFDULL,
1666 0xFDFDFDFDFDFDFDFDULL,
1667 0xFDFDFDFDFDFDFDFDULL,
1668 0xFDFDFDFDFDFDFDFDULL
1669 },
1670 {
1671 0x000000FDFDFDFDFDULL,
1672 0x0000FDFDFDFDFDFDULL,
1673 0x00FDFDFDFDFDFDFDULL,
1674 0xFDFDFDFDFDFDFDFDULL,
1675 0xFDFDFDFDFDFDFDFDULL,
1676 0xFDFDFDFDFDFDFDFDULL,
1677 0xFDFDFDFDFDFDFDFDULL,
1678 0xFDFDFDFDFDFDFDFDULL
1679 },
1680 {
1681 0x0000FDFDFDFDFDFDULL,
1682 0x00FDFDFDFDFDFDFDULL,
1683 0xFDFDFDFDFDFDFDFDULL,
1684 0xFDFDFDFDFDFDFDFDULL,
1685 0xFDFDFDFDFDFDFDFDULL,
1686 0xFDFDFDFDFDFDFDFDULL,
1687 0xFDFDFDFDFDFDFDFDULL,
1688 0xFDFDFDFDFDFDFDFDULL
1689 },
1690 {
1691 0x00FDFDFDFDFDFDFDULL,
1692 0xFDFDFDFDFDFDFDFDULL,
1693 0xFDFDFDFDFDFDFDFDULL,
1694 0xFDFDFDFDFDFDFDFDULL,
1695 0xFDFDFDFDFDFDFDFDULL,
1696 0xFDFDFDFDFDFDFDFDULL,
1697 0xFDFDFDFDFDFDFDFDULL,
1698 0xFDFDFDFDFDFDFDFDULL
1699 },
1700 {
1701 0xFDFDFDFDFDFDFDFDULL,
1702 0xFDFDFDFDFDFDFDFDULL,
1703 0xFDFDFDFDFDFDFDFDULL,
1704 0xFDFDFDFDFDFDFDFDULL,
1705 0xFDFDFDFDFDFDFDFDULL,
1706 0xFDFDFDFDFDFDFDFDULL,
1707 0xFDFDFDFDFDFDFDFDULL,
1708 0xFDFDFDFDFDFDFDFDULL
1709 }
1710 }
1711 };
1712
1713 int32_t black_opening_count=0;
1714 int32_t black_opening_x,black_opening_y;
1715 int32_t black_opening_shape;
1716
1717 1506 int32_t choose_opening_shape()
1718 {
1719 // First, count how many bits are set
1720 1506 int32_t numBits=0;
1721 int32_t bitCounter;
1722
1723
2/2
✓ Branch 0 taken 7530 times.
✓ Branch 1 taken 1506 times.
9036 for(int32_t i=0; i<bosMAX; i++)
1724 {
1725
2/2
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 1722 times.
7530 if(COOLSCROLL&(1<<i))
1726 1722 numBits++;
1727 7530 }
1728
1729 // Shouldn't happen...
1730
1/2
✓ Branch 0 taken 1506 times.
✗ Branch 1 not taken.
1506 if(numBits==0)
1731 return bosCIRCLE;
1732
1733 // Pick a bit
1734 1506 bitCounter=zc_rand()%numBits+1;
1735
1736
2/2
✓ Branch 0 taken 1989 times.
✓ Branch 1 taken 26 times.
2015 for(int32_t i=0; i<bosMAX; i++)
1737 {
1738 // If this bit is set, decrement the bit counter
1739
2/2
✓ Branch 0 taken 353 times.
✓ Branch 1 taken 1636 times.
1989 if(COOLSCROLL&(1<<i))
1740 1636 bitCounter--;
1741
1742 // When the counter hits 0, return a value based on
1743 // which bit it stopped on.
1744 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1745
2/2
✓ Branch 0 taken 1480 times.
✓ Branch 1 taken 509 times.
1989 if(bitCounter==0)
1746 1480 return i;
1747 509 }
1748
1749 // Shouldn't be necessary, but the compiler might complain, at least
1750 26 return bosCIRCLE;
1751 1506 }
1752
1753 396 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1754 {
1755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 396 times.
396 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1756
1757 396 int32_t w=256, h=224;
1758 396 int32_t blockrows=28, blockcolumns=32;
1759 396 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1760
1761
2/2
✓ Branch 0 taken 11088 times.
✓ Branch 1 taken 396 times.
11484 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1762 {
1763
2/2
✓ Branch 0 taken 354816 times.
✓ Branch 1 taken 11088 times.
365904 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1764 {
1765
2/2
✓ Branch 0 taken 147229 times.
✓ Branch 1 taken 207587 times.
354816 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1766 354816 }
1767 11088 }
1768
1769 396 black_opening_count = 66;
1770 396 black_opening_x = x;
1771 396 black_opening_y = y;
1772 396 lensclk = 0;
1773 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1774
1775
1776
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(black_opening_shape == bosFADEBLACK)
1777 {
1778 refreshTints();
1779 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1780 }
1781
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(wait)
1782 {
1783 FFCore.warpScriptCheck();
1784 for(int32_t i=0; i<66; i++)
1785 {
1786 draw_screen(tmpscr);
1787 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1788 advanceframe(true);
1789
1790 if(Quit)
1791 {
1792 break;
1793 }
1794 }
1795 }
1796 396 }
1797
1798 1110 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1799 {
1800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1110 times.
1110 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1801
1802 1110 int32_t w=256, h=224;
1803 1110 int32_t blockrows=28, blockcolumns=32;
1804 1110 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1805
1806
2/2
✓ Branch 0 taken 31080 times.
✓ Branch 1 taken 1110 times.
32190 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1807 {
1808
2/2
✓ Branch 0 taken 994560 times.
✓ Branch 1 taken 31080 times.
1025640 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1809 {
1810
2/2
✓ Branch 0 taken 506240 times.
✓ Branch 1 taken 488320 times.
994560 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1811 994560 }
1812 31080 }
1813
1814 1110 black_opening_count = -66;
1815 1110 black_opening_x = x;
1816 1110 black_opening_y = y;
1817 1110 lensclk = 0;
1818
1/2
✓ Branch 0 taken 1110 times.
✗ Branch 1 not taken.
1110 if(black_opening_shape == bosFADEBLACK)
1819 {
1820 refreshTints();
1821 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1822 }
1823
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 911 times.
1110 if(wait)
1824 {
1825 911 FFCore.warpScriptCheck();
1826
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 60126 times.
61037 for(int32_t i=0; i<66; i++)
1827 {
1828 60126 draw_screen(tmpscr);
1829 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1830 60126 advanceframe(true);
1831
1832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60126 times.
60126 if(Quit)
1833 {
1834 break;
1835 }
1836 60126 }
1837 911 }
1838 1110 }
1839
1840 99396 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1841 {
1842 99396 clear_to_color(tmp_scr,BLACK);
1843 99396 int32_t w=256, h=224;
1844
1845
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 858 times.
✓ Branch 2 taken 594 times.
✓ Branch 3 taken 7656 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 90288 times.
99396 switch(black_opening_shape)
1846 {
1847 case bosOVAL:
1848 {
1849 858 double new_w=(w/2)+abs(w/2-x);
1850 858 double new_h=(h/2)+abs(h/2-y);
1851 858 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1852 858 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1853 858 break;
1854 }
1855
1856 case bosTRIANGLE:
1857 {
1858 594 double new_w=(w/2)+abs(w/2-x);
1859 594 double new_h=(h/2)+abs(h/2-y);
1860 594 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1861 594 double P2= (PI/2);
1862 594 double P23=(2*PI/3);
1863 594 double P43=(4*PI/3);
1864 594 double Pa= (-4*PI*a/(3*max_a));
1865 594 double angle=P2+Pa;
1866 594 double a0=angle;
1867 594 double a2=angle+P23;
1868 594 double a4=angle+P43;
1869 1188 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1870 594 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1871 594 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1872 0);
1873 594 break;
1874 }
1875
1876 case bosSMAS:
1877 {
1878
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 3498 times.
7656 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1879
1880
2/2
✓ Branch 0 taken 214368 times.
✓ Branch 1 taken 7656 times.
222024 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1881 {
1882
2/2
✓ Branch 0 taken 1714944 times.
✓ Branch 1 taken 214368 times.
1929312 for(int32_t linerow=0; linerow<8; ++linerow)
1883 {
1884 1714944 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1885
1886
2/2
✓ Branch 0 taken 54878208 times.
✓ Branch 1 taken 1714944 times.
56593152 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1887 {
1888 164634624 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1889
6/6
✓ Branch 0 taken 39546648 times.
✓ Branch 1 taken 15331560 times.
✓ Branch 2 taken 35934032 times.
✓ Branch 3 taken 18944176 times.
✓ Branch 4 taken 20602472 times.
✓ Branch 5 taken 15331560 times.
54878208 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1890 54878208 [linerow];
1891 54878208 ++triangleline;
1892
1893
2/2
✓ Branch 0 taken 48018432 times.
✓ Branch 1 taken 6859776 times.
54878208 if(linerow==0)
1894 {
1895 6859776 }
1896 54878208 }
1897 1714944 }
1898 214368 }
1899
1900 7656 break;
1901 }
1902
1903 case bosFADEBLACK:
1904 {
1905 if(black_opening_count<0)
1906 {
1907 black_fade(zc_min(-black_opening_count,63));
1908 }
1909 else if(black_opening_count>0)
1910 {
1911 black_fade(63-zc_max(black_opening_count-3,0));
1912 }
1913 else black_fade(0);
1914 return; //no blitting from tmp_scr!
1915 }
1916
1917 90288 case bosCIRCLE:
1918 default:
1919 {
1920 90288 double new_w=(w/2)+abs(w/2-x);
1921 90288 double new_h=(h/2)+abs(h/2-y);
1922 90288 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1923 //circlefill(tmp_scr,x,y,a<<3,0);
1924 90288 circlefill(tmp_scr,x,y,r,0);
1925 90288 break;
1926 }
1927 }
1928
1929 99396 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1930 99396 }
1931
1932
1933 void black_fade(int32_t fadeamnt)
1934 {
1935 for(int32_t i=0; i < 0xEF; i++)
1936 {
1937 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,63);
1938 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,63);
1939 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,63);
1940 }
1941
1942 refreshpal = true;
1943 }
1944
1945 //----------------------------------------------------------------
1946
1947 38818794 bool item_disabled(int32_t item) //is this item disabled?
1948 {
1949
2/2
✓ Branch 0 taken 1832363 times.
✓ Branch 1 taken 36986431 times.
38818794 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1950 }
1951
1952 7617731 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1953 {
1954
2/2
✓ Branch 0 taken 135210 times.
✓ Branch 1 taken 7482521 times.
7617731 if(current_item(item_type, true) >=item)
1955 {
1956 135210 return true;
1957 }
1958
1959 7482521 return false;
1960 7617731 }
1961
1962 25025980 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1963 {
1964
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 26464 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3220277 times.
✓ Branch 6 taken 16170054 times.
✓ Branch 7 taken 5493498 times.
✓ Branch 8 taken 115687 times.
25025980 switch(item_type)
1965 {
1966 case itype_bomb:
1967 case itype_sbomb:
1968 {
1969 int32_t itemid = getItemID(itemsbuf, item_type, it);
1970
1971 if(itemid == -1)
1972 return false;
1973
1974 return (game->get_item(itemid));
1975 }
1976
1977 case itype_clock:
1978 {
1979 26464 int32_t itemid = getItemID(itemsbuf, item_type, it);
1980
1981
2/4
✓ Branch 0 taken 26464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26464 times.
✗ Branch 3 not taken.
26464 if(itemid != -1 && (itemsbuf[itemid].flags & ITEM_FLAG1)) //Active clock
1982 return (game->get_item(itemid));
1983 26464 return Hero.getClock()?1:0;
1984 }
1985
1986 case itype_key:
1987 return (game->get_keys()>0);
1988
1989 case itype_magiccontainer:
1990 return (game->get_maxmagic()>=game->get_mp_per_block());
1991
1992 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1993 {
1994
2/3
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2939741 times.
3220277 switch(it)
1995 {
1996 case -2:
1997 {
1998 for(int32_t i=0; i<MAXLEVELS; i++)
1999 {
2000 if(game->lvlitems[i]&liTRIFORCE)
2001 {
2002 return true;
2003 }
2004 }
2005
2006 return false;
2007 }
2008
2009 case -1:
2010 2939741 return (game->lvlitems[dlevel]&liTRIFORCE);
2011
2012 default:
2013
2/4
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 280536 times.
280536 if(it>=0&&it<MAXLEVELS)
2014 {
2015 280536 return (game->lvlitems[it]&liTRIFORCE);
2016 }
2017
2018 break;
2019 }
2020
2021 return 0;
2022 }
2023
2024 case itype_map: //it: -2=any, -1=current level, other=that level
2025 {
2026
2/3
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15767634 times.
16170054 switch(it)
2027 {
2028 case -2:
2029 {
2030 for(int32_t i=0; i<MAXLEVELS; i++)
2031 {
2032 if(game->lvlitems[i]&liMAP)
2033 {
2034 return true;
2035 }
2036 }
2037
2038 return false;
2039 }
2040
2041 case -1:
2042 15767634 return (game->lvlitems[dlevel]&liMAP)!=0;
2043
2044 default:
2045
2/4
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 402420 times.
402420 if(it>=0&&it<MAXLEVELS)
2046 {
2047 402420 return (game->lvlitems[it]&liMAP)!=0;
2048 }
2049
2050 break;
2051 }
2052
2053 return 0;
2054 }
2055
2056 case itype_compass: //it: -2=any, -1=current level, other=that level
2057 {
2058
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 5493498 times.
5493498 switch(it)
2059 {
2060 case -2:
2061 {
2062 for(int32_t i=0; i<MAXLEVELS; i++)
2063 {
2064 if(game->lvlitems[i]&liCOMPASS)
2065 {
2066 return true;
2067 }
2068 }
2069
2070 return false;
2071 }
2072
2073 case -1:
2074 5493498 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
2075
2076 default:
2077 if(it>=0&&it<MAXLEVELS)
2078 {
2079 return (game->lvlitems[it]&liCOMPASS)!=0;
2080 }
2081
2082 break;
2083 }
2084 return 0;
2085 }
2086
2087 case itype_bosskey: //it: -2=any, -1=current level, other=that level
2088 {
2089
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 115687 times.
115687 switch(it)
2090 {
2091 case -2:
2092 {
2093 for(int32_t i=0; i<MAXLEVELS; i++)
2094 {
2095 if(game->lvlitems[i]&liBOSSKEY)
2096 {
2097 return true;
2098 }
2099 }
2100
2101 return false;
2102 }
2103
2104 case -1:
2105 115687 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
2106
2107 default:
2108 if(it>=0&&it<MAXLEVELS)
2109 {
2110 return (game->lvlitems[it]&liBOSSKEY)?1:0;
2111 }
2112 break;
2113 }
2114 return 0;
2115 }
2116
2117 default:
2118 //it=(1<<(it-1));
2119 /*if (item_type>=itype_max)
2120 {
2121 enter_sys_pal();
2122 jwin_alert("Error","has_item exception",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2123 exit_sys_pal();
2124
2125 return false;
2126 }*/
2127 int32_t itemid = getItemID(itemsbuf, item_type, it);
2128
2129 if(itemid == -1)
2130 return false;
2131
2132 return game->get_item(itemid);
2133 }
2134 25025980 }
2135
2136
2137 51797864 int32_t current_item(int32_t item_type, bool checkenabled) //item currently being used
2138 {
2139
9/9
✓ Branch 0 taken 26464 times.
✓ Branch 1 taken 51586152 times.
✓ Branch 2 taken 26464 times.
✓ Branch 3 taken 26464 times.
✓ Branch 4 taken 26464 times.
✓ Branch 5 taken 26464 times.
✓ Branch 6 taken 26464 times.
✓ Branch 7 taken 26464 times.
✓ Branch 8 taken 26464 times.
51797864 switch(item_type)
2140 {
2141 case itype_clock:
2142 {
2143 26464 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2144
2145
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 26464 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
26464 if(maxid != -1 && (itemsbuf[maxid].flags & ITEM_FLAG1)) //Active clock
2146 return itemsbuf[maxid].fam_type;
2147
2148 26464 return has_item(itype_clock,1) ? 1 : 0;
2149 }
2150
2151 case itype_key:
2152 26464 return game->get_keys();
2153
2154 case itype_lkey:
2155 26464 return game->lvlkeys[get_dlevel()];
2156
2157 case itype_magiccontainer:
2158 26464 return game->get_maxmagic()/game->get_mp_per_block();
2159
2160 case itype_triforcepiece:
2161 {
2162 26464 int32_t count=0;
2163
2164
2/2
✓ Branch 0 taken 13549568 times.
✓ Branch 1 taken 26464 times.
13576032 for(int32_t i=0; i<MAXLEVELS; i++)
2165 {
2166 13549568 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
2167 13549568 }
2168
2169 26464 return count;
2170 }
2171
2172 case itype_map:
2173 {
2174 26464 int32_t count=0;
2175
2176
2/2
✓ Branch 0 taken 13549568 times.
✓ Branch 1 taken 26464 times.
13576032 for(int32_t i=0; i<MAXLEVELS; i++)
2177 {
2178 13549568 count+=(game->lvlitems[i]&liMAP)?1:0;
2179 13549568 }
2180
2181 26464 return count;
2182 }
2183
2184 case itype_compass:
2185 {
2186 26464 int32_t count=0;
2187
2188
2/2
✓ Branch 0 taken 13549568 times.
✓ Branch 1 taken 26464 times.
13576032 for(int32_t i=0; i<MAXLEVELS; i++)
2189 {
2190 13549568 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
2191 13549568 }
2192
2193 26464 return count;
2194 }
2195
2196 case itype_bosskey:
2197 {
2198 26464 int32_t count=0;
2199
2200
2/2
✓ Branch 0 taken 13549568 times.
✓ Branch 1 taken 26464 times.
13576032 for(int32_t i=0; i<MAXLEVELS; i++)
2201 {
2202 13549568 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2203 13549568 }
2204
2205 26464 return count;
2206 }
2207
2208 default:
2209 51586152 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2210
2211
2/2
✓ Branch 0 taken 9872037 times.
✓ Branch 1 taken 41714115 times.
51586152 if(maxid == -1)
2212 41714115 return 0;
2213
2214 9872037 return itemsbuf[maxid].fam_type;
2215 }
2216 51797864 }
2217
2218 44180133 int32_t current_item(int32_t item_type) //item currently being used
2219 {
2220 44180133 return current_item(item_type, true);
2221 }
2222
2223 115 std::map<int32_t, int32_t> itemcache;
2224 115 std::map<int32_t, int32_t> itemcache_cost;
2225
2226 void removeFromItemCache(int32_t itemclass)
2227 {
2228 itemcache.erase(itemclass);
2229 itemcache_cost.erase(itemclass);
2230 cache_tile_mod_clear();
2231 }
2232
2233 5860129 void flushItemCache(bool justcost)
2234 {
2235 5860129 itemcache_cost.clear();
2236
2/2
✓ Branch 0 taken 5830207 times.
✓ Branch 1 taken 29922 times.
5860129 if(!justcost)
2237 29922 itemcache.clear();
2238
2/2
✓ Branch 0 taken 5829775 times.
✓ Branch 1 taken 432 times.
5830207 else if(replay_version_check(0,19))
2239 5829775 return;
2240
2241 30354 cache_tile_mod_clear();
2242
2243 //also fix the active subscreen if items were deleted -DD
2244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30354 times.
30354 if(game != NULL)
2245 {
2246 30354 verifyBothWeapons();
2247 30354 refresh_subscr_items();
2248 30354 }
2249 5860129 }
2250
2251 // This is used often, so it should be as direct as possible.
2252 237599643 int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2253 {
2254 237599643 bool use_cost_cache = replay_version_check(19);
2255
2/2
✓ Branch 0 taken 196193179 times.
✓ Branch 1 taken 41406464 times.
237599643 if(jinx_check)
2256 {
2257
4/4
✓ Branch 0 taken 39645452 times.
✓ Branch 1 taken 1761012 times.
✓ Branch 2 taken 566272 times.
✓ Branch 3 taken 39079180 times.
41406464 if(!(HeroSwordClk() || HeroItemClk()))
2258 39079180 jinx_check = false; //not jinxed
2259 41406464 }
2260
2/2
✓ Branch 0 taken 113585 times.
✓ Branch 1 taken 237486058 times.
237599643 if(!Hero.BunnyClock())
2261 237486058 check_bunny = false; //not bunnied
2262
2/2
✓ Branch 0 taken 214080184 times.
✓ Branch 1 taken 23519459 times.
237599643 if(itemtype == itype_ring) checkmagic = true;
2263
4/4
✓ Branch 0 taken 235272359 times.
✓ Branch 1 taken 2327284 times.
✓ Branch 2 taken 211739537 times.
✓ Branch 3 taken 23238198 times.
472577378 if (!jinx_check && !check_bunny
2264
3/4
✓ Branch 0 taken 235272359 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 234977735 times.
✓ Branch 3 taken 294624 times.
235272359 && (use_cost_cache || itemtype != itype_ring))
2265 {
2266
4/4
✓ Branch 0 taken 171771167 times.
✓ Branch 1 taken 40262994 times.
✓ Branch 2 taken 171609501 times.
✓ Branch 3 taken 161666 times.
212034161 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2267 212034161 auto res = cache.find(itemtype);
2268
2269
2/2
✓ Branch 0 taken 196764427 times.
✓ Branch 1 taken 15269734 times.
212034161 if(res != cache.end())
2270 196764427 return res->second;
2271 15269734 }
2272
2273 40835216 int32_t result = -1;
2274 40835216 int32_t highestlevel = -1;
2275
2276
2/2
✓ Branch 0 taken 10453815296 times.
✓ Branch 1 taken 40835216 times.
10494650512 for(int32_t i=0; i<MAXITEMS; i++)
2277 {
2278
5/6
✓ Branch 0 taken 738540148 times.
✓ Branch 1 taken 9715275148 times.
✓ Branch 2 taken 16221055 times.
✓ Branch 3 taken 722319093 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 16221055 times.
10453815296 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2279 {
2280
4/4
✓ Branch 0 taken 15716917 times.
✓ Branch 1 taken 504138 times.
✓ Branch 2 taken 8694 times.
✓ Branch 3 taken 15708223 times.
16221055 if(checkmagic && itemtype != itype_magicring)
2281
2/2
✓ Branch 0 taken 15708065 times.
✓ Branch 1 taken 158 times.
15708223 if(!checkmagiccost(i))
2282 158 continue;
2283
6/6
✓ Branch 0 taken 14660615 times.
✓ Branch 1 taken 1560282 times.
✓ Branch 2 taken 106359 times.
✓ Branch 3 taken 1453923 times.
✓ Branch 4 taken 863941 times.
✓ Branch 5 taken 696341 times.
16220897 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 696341 times.
696341 if(!(itemsbuf[i].flags & ITEM_JINX_IMMUNE))
2285 696341 continue;
2286
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15524556 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15524556 if(check_bunny && !checkbunny(i))
2287 continue;
2288
2289
2/2
✓ Branch 0 taken 153841 times.
✓ Branch 1 taken 15370715 times.
15524556 if(itemsbuf[i].fam_type >= highestlevel)
2290 {
2291 15370715 highestlevel = itemsbuf[i].fam_type;
2292 15370715 result=i;
2293 15370715 }
2294 15524556 }
2295 10453118797 }
2296
2297
3/4
✓ Branch 0 taken 38507932 times.
✓ Branch 1 taken 2327284 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38507932 times.
40835216 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2298 {
2299
2/2
✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 38503472 times.
38507932 if (use_cost_cache)
2300 {
2301
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 2192 times.
4460 if (!checkmagic)
2302 2192 itemcache[itemtype] = result;
2303
5/6
✓ Branch 0 taken 2192 times.
✓ Branch 1 taken 2268 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2188 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4460 if (checkmagic || result < 0 || checkmagiccost(result))
2304 4460 itemcache_cost[itemtype] = result;
2305 4460 }
2306 else
2307 {
2308 38503472 itemcache[itemtype] = result;
2309 }
2310 38507932 }
2311 40835216 return result;
2312 237599643 }
2313
2314 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2315 235716572 int32_t current_item_id(int32_t itype, bool checkmagic, bool jinx_check, bool check_bunny)
2316 {
2317
2/4
✓ Branch 0 taken 235716572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 235716572 times.
235716572 if(itype < 0 || itype >= itype_max) return -1;
2318
1/2
✓ Branch 0 taken 235716572 times.
✗ Branch 1 not taken.
235716572 if(game->OverrideItems[itype] > -2)
2319 {
2320 auto ovid = game->OverrideItems[itype];
2321 if(ovid < 0 || ovid >= MAXITEMS)
2322 return -1;
2323 if(itemsbuf[ovid].family == itype)
2324 {
2325 if(itype == itype_magicring)
2326 checkmagic = false;
2327 else if(itype == itype_ring)
2328 checkmagic = true;
2329
2330 if(checkmagic && !checkmagiccost(ovid))
2331 return -1;
2332 if(jinx_check && !(itemsbuf[ovid].flags & ITEM_JINX_IMMUNE)
2333 && (usesSwordJinx(ovid) ? HeroSwordClk() : HeroItemClk()))
2334 return -1;
2335 return ovid;
2336 }
2337 }
2338 235716572 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2339
2/2
✓ Branch 0 taken 39523393 times.
✓ Branch 1 taken 196193179 times.
235716572 if(!jinx_check) //If not already a jinx-immune-only check...
2340 {
2341 //And the player IS jinxed...
2342
4/4
✓ Branch 0 taken 194775144 times.
✓ Branch 1 taken 1418035 times.
✓ Branch 2 taken 465036 times.
✓ Branch 3 taken 194310108 times.
196193179 if(HeroSwordClk() || HeroItemClk())
2343 {
2344 //Then do a jinx-immune-only check here
2345 1883071 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2346 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2347 //Should NOT need a compat rule, as this should always return -1 in old quests.
2348
2/2
✓ Branch 0 taken 523190 times.
✓ Branch 1 taken 1359881 times.
1883071 if(ret2 > -1) return ret2;
2349 1359881 }
2350 195669989 }
2351 235193382 return ret;
2352 235716572 }
2353
2354 19471195 int32_t current_item_power(int32_t itemtype)
2355 {
2356 19471195 int32_t result = current_item_id(itemtype,true);
2357
2/2
✓ Branch 0 taken 14106441 times.
✓ Branch 1 taken 5364754 times.
19471195 return (result<0) ? 0 : itemsbuf[result].power;
2358 }
2359
2360 11 int32_t heart_container_id()
2361 {
2362
1/2
✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
319 for(int32_t i=0; i<MAXITEMS; i++)
2363 {
2364
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 308 times.
319 if(itemsbuf[i].family == itype_heartcontainer)
2365 {
2366 11 return i;
2367 }
2368 308 }
2369 return -1;
2370 11 }
2371
2372 struct tilemod_cache_state_t
2373 {
2374
6/6
✓ Branch 0 taken 26144 times.
✓ Branch 1 taken 6026890 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6026888 times.
✓ Branch 4 taken 318 times.
✓ Branch 5 taken 6026570 times.
12079924 bool operator==(const tilemod_cache_state_t&) const = default;
2375
2376 bool valid;
2377 bool bunny_clock;
2378 bool superman;
2379 int shield;
2380 };
2381 tilemod_cache_state_t tilemod_cache_state;
2382 int32_t tilemod_cache_value;
2383
2384 30882 void cache_tile_mod_clear()
2385 {
2386 30882 tilemod_cache_state = {false};
2387 30882 }
2388
2389 6053034 int32_t item_tile_mod()
2390 {
2391 24212136 tilemod_cache_state_t state = {
2392 .valid = true,
2393 6053034 .bunny_clock = Hero.BunnyClock() != 0,
2394 6053034 .superman = Hero.superman,
2395 6053034 .shield = Hero.active_shield_id,
2396 };
2397
2/2
✓ Branch 0 taken 6026570 times.
✓ Branch 1 taken 26464 times.
6053034 if (tilemod_cache_state == state)
2398 6026570 return tilemod_cache_value;
2399
2400 26464 int32_t tile=0;
2401 26464 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2402
3/4
✓ Branch 0 taken 26464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21487 times.
✓ Branch 3 taken 4977 times.
26464 if(check_bombcost || game->get_bombs())
2403 {
2404 21487 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2405
3/4
✓ Branch 0 taken 20338 times.
✓ Branch 1 taken 1149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20338 times.
21487 if(itemid > -1 && checkbunny(itemid))
2406 20338 tile+=itemsbuf[itemid].ltm;
2407 21487 }
2408
2409
3/4
✓ Branch 0 taken 26464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6763 times.
✓ Branch 3 taken 19701 times.
26464 if(check_bombcost || game->get_sbombs())
2410 {
2411 6763 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2412
3/4
✓ Branch 0 taken 6757 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6757 times.
6763 if(itemid > -1 && checkbunny(itemid))
2413 6757 tile+=itemsbuf[itemid].ltm;
2414 6763 }
2415
2416
2/2
✓ Branch 0 taken 25607 times.
✓ Branch 1 taken 857 times.
26464 if(current_item(itype_clock))
2417 {
2418 857 int32_t itemid =
2419
1/2
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
857 get_qr(qr_HARDCODED_LITEM_LTMS)
2420 ? iClock
2421 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2422
2/4
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 857 times.
857 if(itemid > -1 && checkbunny(itemid))
2423 857 tile+=itemsbuf[itemid].ltm;
2424 857 }
2425
2426
2/2
✓ Branch 0 taken 20189 times.
✓ Branch 1 taken 6275 times.
26464 if(current_item(itype_key))
2427 {
2428 6275 int32_t itemid =
2429
1/2
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
6275 get_qr(qr_HARDCODED_LITEM_LTMS)
2430 ? iKey
2431 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2432
2/4
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6275 times.
6275 if(itemid > -1 && checkbunny(itemid))
2433 6275 tile+=itemsbuf[itemid].ltm;
2434 6275 }
2435
2436
2/2
✓ Branch 0 taken 24986 times.
✓ Branch 1 taken 1478 times.
26464 if(current_item(itype_lkey))
2437 {
2438 1478 int32_t itemid =
2439
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 6 times.
1478 get_qr(qr_HARDCODED_LITEM_LTMS)
2440 ? iLevelKey
2441 6 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2442
2/4
✓ Branch 0 taken 1478 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1478 times.
1478 if(itemid > -1 && checkbunny(itemid))
2443 1478 tile+=itemsbuf[itemid].ltm;
2444 1478 }
2445
2446
2/2
✓ Branch 0 taken 5911 times.
✓ Branch 1 taken 20553 times.
26464 if(current_item(itype_map))
2447 {
2448 20553 int32_t itemid =
2449
1/2
✓ Branch 0 taken 20553 times.
✗ Branch 1 not taken.
20553 get_qr(qr_HARDCODED_LITEM_LTMS)
2450 ? iMap
2451 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2452
2/4
✓ Branch 0 taken 20553 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20553 times.
20553 if(itemid > -1 && checkbunny(itemid))
2453 20553 tile+=itemsbuf[itemid].ltm;
2454 20553 }
2455
2456
2/2
✓ Branch 0 taken 5695 times.
✓ Branch 1 taken 20769 times.
26464 if(current_item(itype_compass))
2457 {
2458 20769 int32_t itemid =
2459
2/2
✓ Branch 0 taken 20368 times.
✓ Branch 1 taken 401 times.
20769 get_qr(qr_HARDCODED_LITEM_LTMS)
2460 ? iCompass
2461 401 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2462
2/4
✓ Branch 0 taken 20769 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20769 times.
20769 if(itemid > -1 && checkbunny(itemid))
2463 20769 tile+=itemsbuf[itemid].ltm;
2464 20769 }
2465
2466
2/2
✓ Branch 0 taken 15496 times.
✓ Branch 1 taken 10968 times.
26464 if(current_item(itype_bosskey))
2467 {
2468 10968 int32_t itemid =
2469
1/2
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
10968 get_qr(qr_HARDCODED_LITEM_LTMS)
2470 ? iBossKey
2471 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2472
2/4
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10968 times.
10968 if(itemid > -1 && checkbunny(itemid))
2473 10968 tile+=itemsbuf[itemid].ltm;
2474 10968 }
2475
2476
2/2
✓ Branch 0 taken 13011 times.
✓ Branch 1 taken 13453 times.
26464 if(current_item(itype_magiccontainer))
2477 {
2478 13453 int32_t itemid =
2479
2/2
✓ Branch 0 taken 13001 times.
✓ Branch 1 taken 452 times.
13453 get_qr(qr_HARDCODED_LITEM_LTMS)
2480 ? iMagicC
2481 452 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2482
3/4
✓ Branch 0 taken 13453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 13436 times.
13453 if(itemid > -1 && checkbunny(itemid))
2483 13436 tile+=itemsbuf[itemid].ltm;
2484 13453 }
2485
2486
2/2
✓ Branch 0 taken 7158 times.
✓ Branch 1 taken 19306 times.
26464 if(current_item(itype_triforcepiece))
2487 {
2488 19306 int32_t itemid =
2489
1/2
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
19306 get_qr(qr_HARDCODED_LITEM_LTMS)
2490 ? iTriforce
2491 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2492
2/4
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19306 times.
19306 if(itemid > -1 && checkbunny(itemid))
2493 19306 tile+=itemsbuf[itemid].ltm;
2494 19306 }
2495
2496
2/2
✓ Branch 0 taken 13549568 times.
✓ Branch 1 taken 26464 times.
13576032 for(int32_t i=0; i<itype_max; i++)
2497 {
2498
2/2
✓ Branch 0 taken 13294592 times.
✓ Branch 1 taken 254976 times.
13549568 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2499 {
2500
2/2
✓ Branch 0 taken 4980 times.
✓ Branch 1 taken 249996 times.
254976 switch(i)
2501 {
2502 case itype_bomb:
2503 case itype_sbomb:
2504 case itype_clock:
2505 case itype_key:
2506 case itype_lkey:
2507 case itype_map:
2508 case itype_compass:
2509 case itype_bosskey:
2510 case itype_magiccontainer:
2511 case itype_triforcepiece:
2512 4980 continue; //already handled
2513 }
2514 249996 }
2515 13544588 int32_t itemid = current_item_id(i,false);
2516
2/2
✓ Branch 0 taken 13518124 times.
✓ Branch 1 taken 26464 times.
13544588 if(i == itype_shield)
2517 26464 itemid = getCurrentShield(false);
2518
2519
4/4
✓ Branch 0 taken 353535 times.
✓ Branch 1 taken 13191053 times.
✓ Branch 2 taken 919 times.
✓ Branch 3 taken 352616 times.
13544588 if(itemid < 0 || !checkbunny(itemid))
2520 13191972 continue;
2521
2522 352616 itemdata const& itm = itemsbuf[itemid];
2523
2524
2/2
✓ Branch 0 taken 328701 times.
✓ Branch 1 taken 23915 times.
352616 switch(itm.family)
2525 {
2526 case itype_shield:
2527
1/2
✓ Branch 0 taken 23915 times.
✗ Branch 1 not taken.
23915 if(itm.flags & ITEM_FLAG9) //active shield
2528 {
2529 if(!usingActiveShield(itemid))
2530 {
2531 tile+=itm.misc6; //'Inactive PTM'
2532 continue;
2533 }
2534 }
2535 23915 break;
2536 }
2537
2538 352616 tile+=itm.ltm;
2539 352616 }
2540
2541 26464 tilemod_cache_value = tile;
2542 26464 tilemod_cache_state = state;
2543 26464 return tile;
2544 6053034 }
2545
2546 6053034 int32_t bunny_tile_mod()
2547 {
2548
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 6051164 times.
6053034 if(Hero.BunnyClock())
2549 {
2550 1870 return game->get_bunny_ltm();
2551 }
2552 6051164 return 0;
2553 6053034 }
2554
2555 // Hints are drawn on a separate layer to combo reveals.
2556 16332 void draw_lens_under(BITMAP *dest, bool layer)
2557 {
2558 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2559 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2560 //Lens flag 3: Don't show armos/chest/dive items
2561 //Lens flag 4: Show Raft Paths
2562 //Lens flag 5: Show Invisible Enemies
2563
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 15876 times.
✓ Branch 2 taken 7938 times.
✓ Branch 3 taken 7938 times.
16332 bool hints = (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG1));
2564
2565 16332 int32_t strike_hint_table[11]=
2566 {
2567 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2568 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2569 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2570 };
2571
2572 // int32_t page = tmpscr->cpage;
2573 {
2574 16332 int32_t blink_rate=flash_reduction_enabled()?6:1;
2575 // int32_t temptimer=0;
2576 16332 int32_t tempitem, tempweapon=0;
2577 16332 strike_hint=strike_hint_table[strike_hint_counter];
2578
2579
2/2
✓ Branch 0 taken 15842 times.
✓ Branch 1 taken 490 times.
16332 if(strike_hint_timer>32)
2580 {
2581 490 strike_hint_timer=0;
2582 490 strike_hint_counter=((strike_hint_counter+1)%11);
2583 490 }
2584
2585 16332 ++strike_hint_timer;
2586
2587
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 16332 times.
2890764 for(int32_t i=0; i<176; i++)
2588 {
2589 2874432 int32_t x = (i & 15) << 4;
2590 2874432 int32_t y = (i & 0xF0) + playing_field_offset;
2591 2874432 int32_t tempitemx=-16, tempitemy=-16;
2592 2874432 int32_t tempweaponx=-16, tempweapony=-16;
2593
2594
2/2
✓ Branch 0 taken 5748864 times.
✓ Branch 1 taken 2874432 times.
8623296 for(int32_t iter=0; iter<2; ++iter)
2595 {
2596 5748864 int32_t checkflag=0;
2597
2598
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 2874432 times.
5748864 if(iter==0)
2599 {
2600 2874432 checkflag=combobuf[tmpscr->data[i]].flag;
2601 2874432 }
2602 else
2603 {
2604 2874432 checkflag=tmpscr->sflag[i];
2605 }
2606
2607
2/2
✓ Branch 0 taken 5747766 times.
✓ Branch 1 taken 1098 times.
5748864 if(checkflag==mfSTRIKE)
2608 {
2609
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2610 {
2611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2612 906 }
2613 else
2614 {
2615 192 checkflag = strike_hint;
2616 }
2617 1098 }
2618
2619
20/36
✓ Branch 0 taken 5706470 times.
✓ Branch 1 taken 3148 times.
✓ Branch 2 taken 3618 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2064 times.
✓ Branch 5 taken 28640 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 33 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 5 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
5748864 switch(checkflag)
2620 {
2621 case 0:
2622 case mfZELDA:
2623 case mfPUSHED:
2624 case mfENEMY0:
2625 case mfENEMY1:
2626 case mfENEMY2:
2627 case mfENEMY3:
2628 case mfENEMY4:
2629 case mfENEMY5:
2630 case mfENEMY6:
2631 case mfENEMY7:
2632 case mfENEMY8:
2633 case mfENEMY9:
2634 case mfSINGLE:
2635 case mfSINGLE16:
2636 case mfNOENEMY:
2637 case mfTRAP_H:
2638 case mfTRAP_V:
2639 case mfTRAP_4:
2640 case mfTRAP_LR:
2641 case mfTRAP_UD:
2642 case mfNOGROUNDENEMY:
2643 case mfNOBLOCKS:
2644 case mfSCRIPT1:
2645 case mfSCRIPT2:
2646 case mfSCRIPT3:
2647 case mfSCRIPT4:
2648 case mfSCRIPT5:
2649 case mfSCRIPT6:
2650 case mfSCRIPT7:
2651 case mfSCRIPT8:
2652 case mfSCRIPT9:
2653 case mfSCRIPT10:
2654 case mfSCRIPT11:
2655 case mfSCRIPT12:
2656 case mfSCRIPT13:
2657 case mfSCRIPT14:
2658 case mfSCRIPT15:
2659 case mfSCRIPT16:
2660 case mfSCRIPT17:
2661 case mfSCRIPT18:
2662 case mfSCRIPT19:
2663 case mfSCRIPT20:
2664 case mfPITHOLE:
2665 case mfPITFALLFLOOR:
2666 case mfLAVA:
2667 case mfICE:
2668 case mfICEDAMAGE:
2669 case mfDAMAGE1:
2670 case mfDAMAGE2:
2671 case mfDAMAGE4:
2672 case mfDAMAGE8:
2673 case mfDAMAGE16:
2674 case mfDAMAGE32:
2675 case mfFREEZEALL:
2676 case mfFREZEALLANSFFCS:
2677 case mfFREEZEFFCSOLY:
2678 case mfSCRITPTW1TRIG:
2679 case mfSCRITPTW2TRIG:
2680 case mfSCRITPTW3TRIG:
2681 case mfSCRITPTW4TRIG:
2682 case mfSCRITPTW5TRIG:
2683 case mfSCRITPTW6TRIG:
2684 case mfSCRITPTW7TRIG:
2685 case mfSCRITPTW8TRIG:
2686 case mfSCRITPTW9TRIG:
2687 case mfSCRITPTW10TRIG:
2688 case mfTROWEL:
2689 case mfTROWELNEXT:
2690 case mfTROWELSPECIALITEM:
2691 case mfSLASHPOT:
2692 case mfLIFTPOT:
2693 case mfLIFTORSLASH:
2694 case mfLIFTROCK:
2695 case mfLIFTROCKHEAVY:
2696 case mfDROPITEM:
2697 case mfSPECIALITEM:
2698 case mfDROPKEY:
2699 case mfDROPLKEY:
2700 case mfDROPCOMPASS:
2701 case mfDROPMAP:
2702 case mfDROPBOSSKEY:
2703 case mfSPAWNNPC:
2704 case mfSWITCHHOOK:
2705 case mfSIDEVIEWLADDER:
2706 case mfSIDEVIEWPLATFORM:
2707 case mfNOENEMYSPAWN:
2708 case mfENEMYALL:
2709 case mfNOMIRROR:
2710 case mfUNSAFEGROUND:
2711 case mf168:
2712 case mf169:
2713 case mf170:
2714 case mf171:
2715 case mf172:
2716 case mf173:
2717 case mf174:
2718 case mf175:
2719 case mf176:
2720 case mf177:
2721 case mf178:
2722 case mf179:
2723 case mf180:
2724 case mf181:
2725 case mf182:
2726 case mf183:
2727 case mf184:
2728 case mf185:
2729 case mf186:
2730 case mf187:
2731 case mf188:
2732 case mf189:
2733 case mf190:
2734 case mf191:
2735 case mf192:
2736 case mf193:
2737 case mf194:
2738 case mf195:
2739 case mf196:
2740 case mf197:
2741 case mf198:
2742 case mf199:
2743 case mf200:
2744 case mf201:
2745 case mf202:
2746 case mf203:
2747 case mf204:
2748 case mf205:
2749 case mf206:
2750 case mf207:
2751 case mf208:
2752 case mf209:
2753 case mf210:
2754 case mf211:
2755 case mf212:
2756 case mf213:
2757 case mf214:
2758 case mf215:
2759 case mf216:
2760 case mf217:
2761 case mf218:
2762 case mf219:
2763 case mf220:
2764 case mf221:
2765 case mf222:
2766 case mf223:
2767 case mf224:
2768 case mf225:
2769 case mf226:
2770 case mf227:
2771 case mf228:
2772 case mf229:
2773 case mf230:
2774 case mf231:
2775 case mf232:
2776 case mf233:
2777 case mf234:
2778 case mf235:
2779 case mf236:
2780 case mf237:
2781 case mf238:
2782 case mf239:
2783 case mf240:
2784 case mf241:
2785 case mf242:
2786 case mf243:
2787 case mf244:
2788 case mf245:
2789 case mf246:
2790 case mf247:
2791 case mf248:
2792 case mf249:
2793 case mf250:
2794 case mf251:
2795 case mf252:
2796 case mf253:
2797 case mf254:
2798 case mfEXTENDED:
2799 5706470 break;
2800
2801 case mfPUSHUD:
2802 case mfPUSHLR:
2803 case mfPUSH4:
2804 case mfPUSHU:
2805 case mfPUSHD:
2806 case mfPUSHL:
2807 case mfPUSHR:
2808 case mfPUSHUDNS:
2809 case mfPUSHLRNS:
2810 case mfPUSH4NS:
2811 case mfPUSHUNS:
2812 case mfPUSHDNS:
2813 case mfPUSHLNS:
2814 case mfPUSHRNS:
2815 case mfPUSHUDINS:
2816 case mfPUSHLRINS:
2817 case mfPUSH4INS:
2818 case mfPUSHUINS:
2819 case mfPUSHDINS:
2820 case mfPUSHLINS:
2821 case mfPUSHRINS:
2822
3/4
✓ Branch 0 taken 1829 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
3148 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2823
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1829 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2824 {
2825 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2826 }
2827
2828
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3148 times.
3148 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2829
3/6
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 710 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 710 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3148 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2830 {
2831
2/2
✓ Branch 0 taken 1406 times.
✓ Branch 1 taken 1032 times.
2438 if(hints)
2832 {
2833
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2834 {
2835 case cPUSH_HEAVY:
2836 case cPUSH_HW:
2837 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2838 72 tempitemx=x, tempitemy=y;
2839
2840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2841 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2842
2843 72 break;
2844
2845 case cPUSH_HEAVY2:
2846 case cPUSH_HW2:
2847 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2848 63 tempitemx=x, tempitemy=y;
2849
2850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2851 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2852
2853 63 break;
2854 }
2855 1032 }
2856 2438 }
2857
2858 3148 break;
2859
2860 case mfWHISTLE:
2861
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2862 {
2863 tempitem=getItemID(itemsbuf,itype_whistle,1);
2864
2865 if(tempitem<0) break;
2866
2867 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2868 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2869 {
2870 tempitemx=x;
2871 tempitemy=y;
2872 }
2873
2874 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2875 }
2876
2877 2418 break;
2878
2879 //Why is this here?
2880 case mfFAIRY:
2881 case mfMAGICFAIRY:
2882 case mfALLFAIRY:
2883 if(hints)
2884 {
2885 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2886
2887 if(tempitem < 0) break;
2888
2889 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2890 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2891 {
2892 tempitemx=x;
2893 tempitemy=y;
2894 }
2895
2896 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2897 }
2898
2899 break;
2900
2901 case mfANYFIRE:
2902
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2903 {
2904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2905 252 }
2906 else
2907 {
2908 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2909
2910
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2911
2912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2913
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2914 {
2915 189 tempitemx=x;
2916 189 tempitemy=y;
2917 189 }
2918
2919 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2920 }
2921
2922 504 break;
2923
2924 case mfSTRONGFIRE:
2925 if(!hints)
2926 {
2927 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2928 }
2929 else
2930 {
2931 tempitem=getItemID(itemsbuf,itype_candle,2);
2932
2933 if(tempitem<0) break;
2934
2935 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2936 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2937 {
2938 tempitemx=x;
2939 tempitemy=y;
2940 }
2941
2942 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2943 }
2944
2945 break;
2946
2947 case mfMAGICFIRE:
2948 if(!hints)
2949 {
2950 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2951 }
2952 else
2953 {
2954 tempitem=getItemID(itemsbuf,itype_wand,1);
2955
2956 if(tempitem<0) break;
2957
2958 tempweapon=wFire;
2959
2960 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2961 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2962 {
2963 tempitemx=x;
2964 tempitemy=y;
2965 }
2966 else
2967 {
2968 tempweaponx=x;
2969 tempweapony=y;
2970 }
2971
2972 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2973 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2974 }
2975
2976 break;
2977
2978 case mfDIVINEFIRE:
2979 if(!hints)
2980 {
2981 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2982 }
2983 else
2984 {
2985 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2986
2987 if(tempitem<0) break;
2988
2989 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2990 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2991 {
2992 tempitemx=x;
2993 tempitemy=y;
2994 }
2995
2996 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2997 }
2998
2999 break;
3000
3001 case mfARROW:
3002
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
3003 {
3004
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
3005 732 }
3006 else
3007 {
3008 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
3009
3010
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
3011
3012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3013
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3014 {
3015 61 tempitemx=x;
3016 61 tempitemy=y;
3017 61 }
3018
3019 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3020 }
3021
3022 814 break;
3023
3024 case mfSARROW:
3025 if(!hints)
3026 {
3027 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
3028 }
3029 else
3030 {
3031 tempitem=getItemID(itemsbuf,itype_arrow,2);
3032
3033 if(tempitem<0) break;
3034
3035 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3036 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3037 {
3038 tempitemx=x;
3039 tempitemy=y;
3040 }
3041
3042 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3043 }
3044
3045 break;
3046
3047 case mfGARROW:
3048 if(!hints)
3049 {
3050 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
3051 }
3052 else
3053 {
3054 tempitem=getItemID(itemsbuf,itype_arrow,3);
3055
3056 if(tempitem<0) break;
3057
3058 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3059 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3060 {
3061 tempitemx=x;
3062 tempitemy=y;
3063 }
3064
3065 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3066 }
3067
3068 break;
3069
3070 case mfBOMB:
3071
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 if(!hints)
3072 {
3073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
3074 16 }
3075 else
3076 {
3077 //tempitem=getItemID(itemsbuf,itype_bomb,1);
3078 17 tempweapon = wLitBomb;
3079
3080 //if (tempitem<0) break;
3081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3082
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3083 {
3084 12 tempweaponx=x;
3085 12 tempweapony=y;
3086 12 }
3087
3088 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3089 }
3090
3091 33 break;
3092
3093 case mfSBOMB:
3094
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
3095 {
3096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
3097 48 }
3098 else
3099 {
3100 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
3101 //if (tempitem<0) break;
3102 48 tempweapon = wLitSBomb;
3103
3104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3105
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3106 {
3107 36 tempweaponx=x;
3108 36 tempweapony=y;
3109 36 }
3110
3111 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3112 }
3113
3114 96 break;
3115
3116 case mfARMOS_SECRET:
3117
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
3118 {
3119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3120 12 }
3121 24 break;
3122
3123 case mfBRANG:
3124
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(!hints)
3125 {
3126 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
3127 }
3128 else
3129 {
3130 5 tempitem=getItemID(itemsbuf,itype_brang,1);
3131
3132
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
3133
3134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3135
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3136 {
3137 4 tempitemx=x;
3138 4 tempitemy=y;
3139 4 }
3140
3141 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3142 }
3143
3144 5 break;
3145
3146 case mfMBRANG:
3147 if(!hints)
3148 {
3149 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
3150 }
3151 else
3152 {
3153 tempitem=getItemID(itemsbuf,itype_brang,2);
3154
3155 if(tempitem<0) break;
3156
3157 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3158 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3159 {
3160 tempitemx=x;
3161 tempitemy=y;
3162 }
3163
3164 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3165 }
3166
3167 break;
3168
3169 case mfFBRANG:
3170 if(!hints)
3171 {
3172 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
3173 }
3174 else
3175 {
3176 tempitem=getItemID(itemsbuf,itype_brang,3);
3177
3178 if(tempitem<0) break;
3179
3180 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3181 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3182 {
3183 tempitemx=x;
3184 tempitemy=y;
3185 }
3186
3187 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3188 }
3189
3190 break;
3191
3192 case mfWANDMAGIC:
3193 if(!hints)
3194 {
3195 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3196 }
3197 else
3198 {
3199 tempitem=getItemID(itemsbuf,itype_wand,1);
3200
3201 if(tempitem<0) break;
3202
3203 tempweapon=itemsbuf[tempitem].wpn3;
3204
3205 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3206 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3207 {
3208 tempitemx=x;
3209 tempitemy=y;
3210 }
3211 else
3212 {
3213 tempweaponx=x;
3214 tempweapony=y;
3215 --lens_hint_weapon[wMagic][4];
3216
3217 if(lens_hint_weapon[wMagic][4]<-8)
3218 {
3219 lens_hint_weapon[wMagic][4]=8;
3220 }
3221 }
3222
3223 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3224 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3225 }
3226
3227 break;
3228
3229 case mfREFMAGIC:
3230
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3231 {
3232 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3233 }
3234 else
3235 {
3236 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3237
3238
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3239
3240 16 tempweapon=ewMagic;
3241
3242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3243
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3244 {
3245 13 tempitemx=x;
3246 13 tempitemy=y;
3247 13 }
3248 else
3249 {
3250 3 tempweaponx=x;
3251 3 tempweapony=y;
3252
3253
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3254 {
3255 1 --lens_hint_weapon[ewMagic][4];
3256 1 }
3257 else
3258 {
3259 2 ++lens_hint_weapon[ewMagic][4];
3260 }
3261
3262
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3263 {
3264 lens_hint_weapon[ewMagic][2]=up;
3265 }
3266
3267
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3268 {
3269 2 lens_hint_weapon[ewMagic][2]=down;
3270 2 }
3271 }
3272
3273 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3274 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3275 }
3276
3277 16 break;
3278
3279 case mfREFFIREBALL:
3280
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3281 {
3282 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3283 }
3284 else
3285 {
3286 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3287
3288
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3289
3290 16 tempweapon=ewFireball;
3291
3292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3293
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3294 {
3295 12 tempitemx=x;
3296 12 tempitemy=y;
3297 12 tempweaponx=x;
3298 12 tempweapony=y;
3299 12 ++lens_hint_weapon[ewFireball][3];
3300
3301
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3302 {
3303 1 lens_hint_weapon[ewFireball][3]=-8;
3304 1 lens_hint_weapon[ewFireball][4]=8;
3305 1 }
3306
3307
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3308 {
3309 8 ++lens_hint_weapon[ewFireball][4];
3310 8 }
3311 else
3312 {
3313 4 --lens_hint_weapon[ewFireball][4];
3314 }
3315 12 }
3316
3317 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3318 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3319 }
3320
3321 16 break;
3322
3323 case mfSWORD:
3324
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3325 {
3326 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3327 }
3328 else
3329 {
3330 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3331
3332
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3333
3334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3335
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3336 {
3337 5 tempitemx=x;
3338 5 tempitemy=y;
3339 5 }
3340
3341 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3342 }
3343
3344 7 break;
3345
3346 case mfWSWORD:
3347 if(!hints)
3348 {
3349 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3350 }
3351 else
3352 {
3353 tempitem=getItemID(itemsbuf,itype_sword,2);
3354
3355 if(tempitem<0) break;
3356
3357 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3358 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3359 {
3360 tempitemx=x;
3361 tempitemy=y;
3362 }
3363
3364 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3365 }
3366
3367 break;
3368
3369 case mfMSWORD:
3370 if(!hints)
3371 {
3372 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3373 }
3374 else
3375 {
3376 tempitem=getItemID(itemsbuf,itype_sword,3);
3377
3378 if(tempitem<0) break;
3379
3380 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3381 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3382 {
3383 tempitemx=x;
3384 tempitemy=y;
3385 }
3386
3387 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3388 }
3389
3390 break;
3391
3392 case mfXSWORD:
3393 if(!hints)
3394 {
3395 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3396 }
3397 else
3398 {
3399 tempitem=getItemID(itemsbuf,itype_sword,4);
3400
3401 if(tempitem<0) break;
3402
3403 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3404 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3405 {
3406 tempitemx=x;
3407 tempitemy=y;
3408 }
3409
3410 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3411 }
3412
3413 break;
3414
3415 case mfSWORDBEAM:
3416
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3417 {
3418 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3419 }
3420 else
3421 {
3422 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3423
3424
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3425
3426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3427
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3428 {
3429 11 tempitemx=x;
3430 11 tempitemy=y;
3431 11 }
3432
3433 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3434 }
3435
3436 16 break;
3437
3438 case mfWSWORDBEAM:
3439 if(!hints)
3440 {
3441 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3442 }
3443 else
3444 {
3445 tempitem=getItemID(itemsbuf,itype_sword,2);
3446
3447 if(tempitem<0) break;
3448
3449 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3450 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3451 {
3452 tempitemx=x;
3453 tempitemy=y;
3454 }
3455
3456 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3457 }
3458
3459 break;
3460
3461 case mfMSWORDBEAM:
3462 if(!hints)
3463 {
3464 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3465 }
3466 else
3467 {
3468 tempitem=getItemID(itemsbuf,itype_sword,3);
3469
3470 if(tempitem<0) break;
3471
3472 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3473 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3474 {
3475 tempitemx=x;
3476 tempitemy=y;
3477 }
3478
3479 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3480 }
3481
3482 break;
3483
3484 case mfXSWORDBEAM:
3485 if(!hints)
3486 {
3487 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3488 }
3489 else
3490 {
3491 tempitem=getItemID(itemsbuf,itype_sword,4);
3492
3493 if(tempitem<0) break;
3494
3495 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3496 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3497 {
3498 tempitemx=x;
3499 tempitemy=y;
3500 }
3501
3502 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3503 }
3504
3505 break;
3506
3507 case mfHOOKSHOT:
3508
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3509 {
3510 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3511 }
3512 else
3513 {
3514 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3515
3516
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3517
3518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3519
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3520 {
3521 12 tempitemx=x;
3522 12 tempitemy=y;
3523 12 }
3524
3525 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3526 }
3527
3528 17 break;
3529
3530 case mfWAND:
3531
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3532 {
3533 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3534 }
3535 else
3536 {
3537 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3538
3539
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3540
3541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3542
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3543 {
3544 28 tempitemx=x;
3545 28 tempitemy=y;
3546 28 }
3547
3548 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3549 }
3550
3551 35 break;
3552
3553 case mfHAMMER:
3554
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3555 {
3556 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3557 }
3558 else
3559 {
3560 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3561
3562
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3563
3564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3565
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3566 {
3567 13 tempitemx=x;
3568 13 tempitemy=y;
3569 13 }
3570
3571 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3572 }
3573
3574 17 break;
3575
3576 case mfARMOS_ITEM:
3577 case mfDIVE_ITEM:
3578
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2064 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2064 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG3))
3579 {
3580 2064 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3581 2064 }
3582 2064 break;
3583
3584 case 16:
3585 case 17:
3586 case 18:
3587 case 19:
3588 case 20:
3589 case 21:
3590 case 22:
3591 case 23:
3592 case 24:
3593 case 25:
3594 case 26:
3595 case 27:
3596 case 28:
3597 case 29:
3598 case 30:
3599 case 31:
3600
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 2610 times.
3618 if(!hints)
3601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2610 times.
5220 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3602 2610 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3603
3604 3618 break;
3605 case mfSECRETSNEXT:
3606 if(!hints)
3607 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3608 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3609
3610 break;
3611
3612 case mfSTRIKE:
3613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3614 {
3615 906 goto special;
3616 }
3617 else
3618 {
3619 break;
3620 }
3621
3622 28640 default: goto special;
3623
3624 special:
3625
8/8
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 14869 times.
✓ Branch 2 taken 473 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 441 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29546 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG4)))
3626 {
3627
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6549 times.
✓ Branch 2 taken 4913 times.
✓ Branch 3 taken 1636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1636 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6549 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3628 {
3629 4913 rectfill(dest,x,y,x+15,y+15,WHITE);
3630 4913 }
3631 6549 }
3632
3633 29546 break;
3634 }
3635 5748864 }
3636 2874432 }
3637
3638
2/2
✓ Branch 0 taken 8166 times.
✓ Branch 1 taken 8166 times.
16332 if(layer)
3639 {
3640
2/2
✓ Branch 0 taken 7978 times.
✓ Branch 1 taken 188 times.
8166 if(tmpscr->door[0]==dWALK)
3641 188 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3642
3643
2/2
✓ Branch 0 taken 7969 times.
✓ Branch 1 taken 197 times.
8166 if(tmpscr->door[1]==dWALK)
3644 197 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3645
3646
2/2
✓ Branch 0 taken 8014 times.
✓ Branch 1 taken 152 times.
8166 if(tmpscr->door[2]==dWALK)
3647 152 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3648
3649
2/2
✓ Branch 0 taken 7940 times.
✓ Branch 1 taken 226 times.
8166 if(tmpscr->door[3]==dWALK)
3650 226 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3651
3652
2/2
✓ Branch 0 taken 8123 times.
✓ Branch 1 taken 43 times.
8166 if(tmpscr->door[0]==dBOMB)
3653 {
3654 43 showbombeddoor(dest, 0);
3655 43 }
3656
3657
2/2
✓ Branch 0 taken 8127 times.
✓ Branch 1 taken 39 times.
8166 if(tmpscr->door[1]==dBOMB)
3658 {
3659 39 showbombeddoor(dest, 1);
3660 39 }
3661
3662
1/2
✓ Branch 0 taken 8166 times.
✗ Branch 1 not taken.
8166 if(tmpscr->door[2]==dBOMB)
3663 {
3664 showbombeddoor(dest, 2);
3665 }
3666
3667
2/2
✓ Branch 0 taken 8129 times.
✓ Branch 1 taken 37 times.
8166 if(tmpscr->door[3]==dBOMB)
3668 {
3669 37 showbombeddoor(dest, 3);
3670 37 }
3671 8166 }
3672
3673
2/2
✓ Branch 0 taken 14298 times.
✓ Branch 1 taken 2034 times.
16332 if(tmpscr->stairx + tmpscr->stairy)
3674 {
3675
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3676 {
3677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3678 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3679 1123 }
3680 else
3681 {
3682
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3683 {
3684 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3685 48 int32_t tempitemx=-16;
3686 48 int32_t tempitemy=-16;
3687
3688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3689
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3690 {
3691 24 tempitemx=tmpscr->stairx;
3692 24 tempitemy=tmpscr->stairy+playing_field_offset;
3693 24 }
3694
3695 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3696 48 }
3697 }
3698 2034 }
3699 }
3700 16332 }
3701
3702 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3703
3704 7997 void draw_lens_over()
3705 {
3706 // Oh, what the heck.
3707 static BITMAP *lens_scr = NULL;
3708 static int32_t last_width = -1;
3709 7997 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3710
3711 // Only redraw the circle if the size has changed
3712
2/2
✓ Branch 0 taken 7987 times.
✓ Branch 1 taken 10 times.
7997 if(width != last_width)
3713 {
3714
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(lens_scr == NULL)
3715 {
3716 10 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3717 10 }
3718
3719 10 clear_to_color(lens_scr, BLACK);
3720 10 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3721 10 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3722 10 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3723 10 last_width=width;
3724 10 }
3725
3726 7997 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3727 7997 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3728 7997 }
3729
3730 //----------------------------------------------------------------
3731
3732 31111 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3733 {
3734 //recreating a big bitmap every frame is highly sluggish.
3735
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
31111 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3736 31111 clear_to_color(wavebuf, BLACK);
3737 31111 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3738
3739 int32_t ofs;
3740 // int32_t amplitude=8;
3741 // int32_t wavelength=4;
3742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31111 times.
31111 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3743
3/6
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3744 31111 int32_t amp2=168;
3745
2/4
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3746 31111 int32_t i=frame%amp2;
3747
3748
2/2
✓ Branch 0 taken 5226648 times.
✓ Branch 1 taken 31111 times.
5257759 for(int32_t j=0; j<168; j++)
3749 {
3750
3/4
✓ Branch 0 taken 2613324 times.
✓ Branch 1 taken 2613324 times.
✓ Branch 2 taken 2613324 times.
✗ Branch 3 not taken.
5226648 if(j&1 && interpol)
3751 {
3752 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3753 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3754 }
3755 else
3756 {
3757 5226648 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3758 }
3759
3760
1/2
✓ Branch 0 taken 5226648 times.
✗ Branch 1 not taken.
5226648 if(ofs)
3761 {
3762
2/2
✓ Branch 0 taken 1338021888 times.
✓ Branch 1 taken 5226648 times.
1343248536 for(int32_t k=0; k<256; k++)
3763 {
3764 1338021888 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3765 1338021888 }
3766 5226648 }
3767 5226648 }
3768 31111 }
3769
3770 4848 void draw_fuzzy(int32_t fuzz)
3771 // draws from right half of scrollbuf to framebuf
3772 {
3773 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3774 byte *start, *si, *di;
3775
3776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4848 times.
4848 if(fuzz<1)
3777 fuzz = 1;
3778
3779 4848 xstep = 128%fuzz;
3780
3781
2/2
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 3838 times.
4848 if(xstep > 0)
3782 3838 xstep = fuzz-xstep;
3783
3784 4848 ystep = 112%fuzz;
3785
3786
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 3434 times.
4848 if(ystep > 0)
3787 3434 ystep = fuzz-ystep;
3788
3789 4848 firsty = 1;
3790
3791
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 174932 times.
179780 for(y=0; y<224;)
3792 {
3793 174932 start = &(scrollbuf->line[y][256]);
3794
3795
4/4
✓ Branch 0 taken 172508 times.
✓ Branch 1 taken 1088376 times.
✓ Branch 2 taken 1085952 times.
✓ Branch 3 taken 174932 times.
1260884 for(dy=0; dy<ystep && dy+y<224; dy++)
3796 {
3797 1085952 si = start;
3798 1085952 di = &(framebuf->line[y+dy][0]);
3799 1085952 i = xstep;
3800 1085952 firstx = 1;
3801
3802
2/2
✓ Branch 0 taken 278003712 times.
✓ Branch 1 taken 1085952 times.
279089664 for(dx=0; dx<256; dx++)
3803 {
3804 278003712 *(di++) = *si;
3805
3806
2/2
✓ Branch 0 taken 234248896 times.
✓ Branch 1 taken 43754816 times.
278003712 if(++i >= fuzz)
3807 {
3808
2/2
✓ Branch 0 taken 42668864 times.
✓ Branch 1 taken 1085952 times.
43754816 if(!firstx)
3809 42668864 si += fuzz;
3810 else
3811 {
3812 1085952 si += fuzz-xstep;
3813 1085952 firstx = 0;
3814 }
3815
3816 43754816 i = 0;
3817 43754816 }
3818 278003712 }
3819 1085952 }
3820
3821
2/2
✓ Branch 0 taken 170084 times.
✓ Branch 1 taken 4848 times.
174932 if(!firsty)
3822 170084 y += fuzz;
3823 else
3824 {
3825 4848 y += ystep;
3826 4848 ystep = fuzz;
3827 4848 firsty = 0;
3828 }
3829 }
3830 4848 }
3831
3832 9286216 void updatescr(bool allowwavy)
3833 {
3834
4/6
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 9286101 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 115 times.
✓ Branch 4 taken 115 times.
✗ Branch 5 not taken.
9286216 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3835
4/6
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 9286101 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 115 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 115 times.
9286216 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3836
3837
2/2
✓ Branch 0 taken 9259451 times.
✓ Branch 1 taken 26765 times.
9286216 if(toogam)
3838 {
3839 26765 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3840 26765 }
3841
3842
1/2
✓ Branch 0 taken 9286216 times.
✗ Branch 1 not taken.
9286216 if(Showpal)
3843 dump_pal(framebuf);
3844
3845
2/2
✓ Branch 0 taken 8984984 times.
✓ Branch 1 taken 301232 times.
9286216 if(!Playing)
3846 301232 black_opening_count=0;
3847
3848
2/2
✓ Branch 0 taken 9212956 times.
✓ Branch 1 taken 73260 times.
9286216 if(black_opening_count<0) //shape is opening up
3849 {
3850 73260 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3851
3852
2/4
✓ Branch 0 taken 73260 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73260 times.
73260 if(Advance||(!Paused))
3853 {
3854 73260 ++black_opening_count;
3855 73260 }
3856 73260 }
3857
2/2
✓ Branch 0 taken 9186820 times.
✓ Branch 1 taken 26136 times.
9212956 else if(black_opening_count>0) //shape is closing
3858 {
3859 26136 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3860
3861
2/4
✓ Branch 0 taken 26136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26136 times.
26136 if(Advance||(!Paused))
3862 {
3863 26136 --black_opening_count;
3864 26136 }
3865 26136 }
3866
3867
3/4
✓ Branch 0 taken 9188326 times.
✓ Branch 1 taken 97890 times.
✓ Branch 2 taken 9188326 times.
✗ Branch 3 not taken.
9286216 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3868 {
3869 black_opening_shape = bosCIRCLE;
3870 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3871 refreshTints();
3872 refreshpal=true;
3873 }
3874
3875
2/2
✓ Branch 0 taken 9032017 times.
✓ Branch 1 taken 254199 times.
9286216 if(refreshpal)
3876 {
3877 254199 refreshpal=false;
3878 254199 RAMpal[253] = _RGB(0,0,0);
3879 254199 RAMpal[254] = _RGB(63,63,63);
3880 254199 hw_palette = &RAMpal;
3881 254199 update_hw_pal = true;
3882
3883 254199 create_rgb_table(&rgb_table, RAMpal, NULL);
3884 254199 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3885 254199 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
3886
3887
2/2
✓ Branch 0 taken 65074944 times.
✓ Branch 1 taken 254199 times.
65329143 for(int32_t q=0; q<PAL_SIZE; q++)
3888 {
3889 65074944 trans_table2.data[0][q] = q;
3890 65074944 trans_table2.data[q][q] = q;
3891 65074944 }
3892 254199 }
3893
3894 9286216 bool clearwavy = (wavy <= 0);
3895
3896
2/2
✓ Branch 0 taken 7655 times.
✓ Branch 1 taken 9278561 times.
9286216 if(wavy <= 0)
3897 {
3898 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3899 9278561 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3900 9278561 }
3901
3902 9286216 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3903
3904
6/6
✓ Branch 0 taken 31361 times.
✓ Branch 1 taken 9254855 times.
✓ Branch 2 taken 31239 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31111 times.
9286216 if(wavy && Playing && allowwavy)
3905 {
3906 31111 draw_wavy(framebuf, wavybuf, wavy,false);
3907 31111 }
3908
3909
2/2
✓ Branch 0 taken 9278561 times.
✓ Branch 1 taken 7655 times.
9286216 if(clearwavy)
3910 9278561 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3911
2/4
✓ Branch 0 taken 7655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7655 times.
7655 else if(Playing && !Paused)
3912 7655 wavy--; // Wavy was set by a script. Decrement it.
3913
3914
5/6
✓ Branch 0 taken 8984984 times.
✓ Branch 1 taken 301232 times.
✓ Branch 2 taken 259415 times.
✓ Branch 3 taken 8725569 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259415 times.
9286216 if(Playing && msgpos && !screenscrolling)
3915 {
3916
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_bg_display_buf->clip))
3917 259415 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3918
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_portrait_display_buf->clip))
3919 259415 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3920
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_txt_display_buf->clip))
3921 259415 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3922 259415 }
3923
3924 /*
3925 if(!(msg_txt_display_buf->clip) && Playing && msgpos && !screenscrolling)
3926 {
3927 BITMAP* subBmp = 0;
3928 masked_blit(msg_txt_display_buf,subBmp,0,0,0,playing_field_offset,256,168);
3929 // masked_blit(msg_txt_display_buf,subBmp,0,playing_field_offset,256,168);
3930 draw_trans_sprite(framebuf, subBmp, 0, playing_field_offset);
3931 destroy_bitmap(subBmp);
3932 //void draw_sprite_ex(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t mode, int32_t flip);
3933 // masked_blit(msg_txt_display_buf,framebuf,0,0,0,playing_field_offset,256,168);
3934 //void masked_blit(BITMAP *source, BITMAP *dest, int32_t source_x, int32_t source_y, int32_t dest_x, int32_t dest_y, int32_t width, int32_t height);
3935 }
3936 */
3937
3938
2/2
✓ Branch 0 taken 9245159 times.
✓ Branch 1 taken 41057 times.
9286216 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3939
3940
2/2
✓ Branch 0 taken 9249784 times.
✓ Branch 1 taken 36432 times.
9286216 if(nosubscr)
3941 {
3942 36432 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3943 36432 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3944 36432 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3945 36432 }
3946
3947 //TODO: Optimize blit 'overcalls' -Gleeok
3948
2/2
✓ Branch 0 taken 36432 times.
✓ Branch 1 taken 9249784 times.
9286216 BITMAP *source = nosubscr ? panorama : wavybuf;
3949 9286216 blit(source,framebuf,0,0,0,0,256,224);
3950
3951 9286216 update_hw_screen();
3952 9286216 }
3953
3954 //----------------------------------------------------------------
3955
3956 static PALETTE syspal;
3957 int32_t onGUISnapshot()
3958 {
3959 char buf[200];
3960 int32_t num=0;
3961 bool realpal=(CHECK_CTRL_CMD);
3962 do
3963 {
3964 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3965 }
3966 while(num<99999 && exists(buf));
3967
3968 BITMAP *b = create_bitmap_ex(8,resx,resy);
3969
3970 if(b)
3971 {
3972 blit(screen,b,0,0,0,0,resx,resy);
3973 save_bitmap(buf,screen,RAMpal);
3974 destroy_bitmap(b);
3975 }
3976
3977 return D_O_K;
3978 }
3979
3980 int32_t onNonGUISnapshot()
3981 {
3982 PALETTE temppal;
3983 get_palette(temppal);
3984 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3985
3986 char buf[200];
3987 int32_t num=0;
3988
3989 do
3990 {
3991 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3992 }
3993 while(num<99999 && exists(buf));
3994
3995 if (tmpscr->flags3&fNOSUBSCR && !(key[KEY_ALT]))
3996 {
3997 BITMAP *b = create_bitmap_ex(8,256,168);
3998 clear_to_color(b,0);
3999 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
4000 save_bitmap(buf,b,realpal?temppal:RAMpal);
4001 destroy_bitmap(b);
4002 }
4003 else
4004 {
4005 save_bitmap(buf,framebuf,realpal?temppal:RAMpal);
4006 }
4007
4008 return D_O_K;
4009 }
4010
4011 int32_t onSnapshot()
4012 {
4013 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
4014 {
4015 onGUISnapshot();
4016 }
4017 else
4018 {
4019 onNonGUISnapshot();
4020 }
4021
4022 return D_O_K;
4023 }
4024
4025 int32_t onSaveMapPic()
4026 {
4027 int32_t mapres2 = 0;
4028 char buf[200];
4029 int32_t num=0;
4030 mapscr tmpscr_b[2];
4031 mapscr tmpscr_c[6];
4032 BITMAP* _screen_draw_buffer = NULL;
4033 _screen_draw_buffer = create_bitmap_ex(8,256,224);
4034 set_clip_state(_screen_draw_buffer,1);
4035
4036 for(int32_t i=0; i<6; ++i)
4037 {
4038 tmpscr_c[i] = tmpscr2[i];
4039 tmpscr2[i].zero_memory();
4040
4041 if(i>=2)
4042 {
4043 continue;
4044 }
4045
4046 tmpscr_b[i] = tmpscr[i];
4047 tmpscr[i].zero_memory();
4048 }
4049
4050 do
4051 {
4052 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
4053 }
4054 while(num<99999 && exists(buf));
4055
4056 BITMAP* mappic = NULL;
4057
4058
4059 bool done=false, redraw=true;
4060
4061 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
4062
4063 if(!mappic)
4064 {
4065 enter_sys_pal();
4066 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4067 exit_sys_pal();
4068 return D_O_K;;
4069 }
4070
4071 // draw the map
4072 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
4073
4074 for(int32_t y=0; y<8; y++)
4075 {
4076 for(int32_t x=0; x<16; x++)
4077 {
4078 if(!displayOnMap(x, y))
4079 {
4080 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
4081 }
4082 else
4083 {
4084 int32_t s = (y<<4) + x;
4085 loadscr2(1,s,-1);
4086
4087 for(int32_t i=0; i<6; i++)
4088 {
4089 if(tmpscr[1].layermap[i]<=0)
4090 continue;
4091
4092 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
4093 }
4094
4095 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4096
4097 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4098
4099 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
4100 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
4101
4102 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4103
4104 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
4105 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4106 {
4107 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
4108 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4109 {
4110 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
4111 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
4112 }
4113 }
4114 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
4115
4116 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4117
4118 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
4119 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
4120 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4121 {
4122 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
4123 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
4124 }
4125 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
4126 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
4127
4128 }
4129
4130 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
4131 }
4132 }
4133
4134 for(int32_t i=0; i<6; ++i)
4135 {
4136 tmpscr2[i]=tmpscr_c[i];
4137
4138 if(i>=2)
4139 {
4140 continue;
4141 }
4142
4143 tmpscr[i]=tmpscr_b[i];
4144 }
4145
4146 save_bitmap(buf,mappic,RAMpal);
4147 destroy_bitmap(mappic);
4148 destroy_bitmap(_screen_draw_buffer);
4149 return D_O_K;
4150 }
4151
4152 14 void f_Quit(int32_t type)
4153 {
4154
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 if(type==qQUIT && !Playing)
4155 return;
4156
4157 14 bool from_menu = is_sys_pal;
4158
4159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4160 {
4161 14 music_pause();
4162 14 pause_all_sfx();
4163 14 sys_mouse();
4164 14 }
4165 14 enter_sys_pal();
4166 14 clear_keybuf();
4167
4168
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (replay_version_check(0, 10))
4169 13 replay_poll();
4170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (replay_is_replaying())
4171 14 replay_peek_quit();
4172
4173
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (!replay_is_replaying())
4174 switch(type)
4175 {
4176 case qQUIT:
4177 onQuit();
4178 break;
4179
4180 case qRESET:
4181 onReset();
4182 break;
4183
4184 case qEXIT:
4185 onExit();
4186 break;
4187 }
4188
4189
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(Quit)
4190 {
4191 14 kill_sfx();
4192 14 music_stop();
4193 14 exit_sys_pal();
4194 14 update_hw_screen();
4195 14 }
4196 else
4197 {
4198 exit_sys_pal();
4199 if(!from_menu)
4200 {
4201 music_resume();
4202 resume_all_sfx();
4203 }
4204 }
4205
4206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4207 14 game_mouse();
4208 14 eat_buttons();
4209
4210 14 zc_readrawkey(KEY_ESC);
4211
4212 14 zc_readrawkey(KEY_ENTER);
4213 14 }
4214
4215 //----------------------------------------------------------------
4216
4217 int32_t onNoWalls()
4218 {
4219 cheats_enqueue(Cheat::Walls);
4220 return D_O_K;
4221 }
4222
4223 int32_t onIgnoreSideview()
4224 {
4225 cheats_enqueue(Cheat::IgnoreSideView);
4226 return D_O_K;
4227 }
4228
4229 9286090 int32_t input_idle(bool checkmouse)
4230 {
4231 static int32_t mx, my, mz, mb;
4232
4233
4/6
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461435 times.
✓ Branch 3 taken 6824655 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2461435 times.
11747525 if(keypressed() || zc_key_pressed() ||
4234
4/8
✓ Branch 0 taken 2461435 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461435 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2461435 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2461435 times.
✗ Branch 7 not taken.
2461435 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4235 {
4236 6824655 idle_count = 0;
4237
4238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6824655 times.
6824655 if(active_count < MAX_ACTIVE)
4239 {
4240 6824655 ++active_count;
4241 6824655 }
4242 6824655 }
4243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2461435 times.
2461435 else if(idle_count < MAX_IDLE)
4244 {
4245 2461435 ++idle_count;
4246 2461435 active_count = 0;
4247 2461435 }
4248
4249 9286090 mx = mouse_x;
4250 9286090 my = mouse_y;
4251 9286090 mz = mouse_z;
4252 9286090 mb = mouse_b;
4253
4254 9286090 return idle_count;
4255 }
4256
4257 int32_t onGoFast()
4258 {
4259 cheats_enqueue(Cheat::Fast);
4260 return D_O_K;
4261 }
4262
4263 int32_t onKillCheat()
4264 {
4265 cheats_enqueue(Cheat::Kill);
4266 return D_O_K;
4267 }
4268
4269 int32_t onSecretsCheat()
4270 {
4271 cheats_enqueue(Cheat::TrigSecrets);
4272 return D_O_K;
4273 }
4274 int32_t onSecretsCheatPerm()
4275 {
4276 cheats_enqueue(Cheat::TrigSecretsPerm);
4277 return D_O_K;
4278 }
4279
4280 int32_t onShowLayer0()
4281 {
4282 show_layer_0 = !show_layer_0;
4283 return D_O_K;
4284 }
4285 int32_t onShowLayer1()
4286 {
4287 show_layer_1 = !show_layer_1;
4288 return D_O_K;
4289 }
4290 int32_t onShowLayer2()
4291 {
4292 show_layer_2 = !show_layer_2;
4293 return D_O_K;
4294 }
4295 int32_t onShowLayer3()
4296 {
4297 show_layer_3 = !show_layer_3;
4298 return D_O_K;
4299 }
4300 int32_t onShowLayer4()
4301 {
4302 show_layer_4 = !show_layer_4;
4303 return D_O_K;
4304 }
4305 int32_t onShowLayer5()
4306 {
4307 show_layer_5 = !show_layer_5;
4308 return D_O_K;
4309 }
4310 int32_t onShowLayer6()
4311 {
4312 show_layer_6 = !show_layer_6;
4313 return D_O_K;
4314 }
4315 int32_t onShowLayerO()
4316 {
4317 show_layer_over=!show_layer_over;
4318 return D_O_K;
4319 }
4320 int32_t onShowLayerP()
4321 {
4322 show_layer_push=!show_layer_push;
4323 return D_O_K;
4324 }
4325 int32_t onShowLayerS()
4326 {
4327 show_sprites=!show_sprites;
4328 return D_O_K;
4329 }
4330 int32_t onShowLayerF()
4331 {
4332 show_ffcs=!show_ffcs;
4333 return D_O_K;
4334 }
4335 int32_t onShowLayerW()
4336 {
4337 show_walkflags=!show_walkflags;
4338 if(show_walkflags)
4339 show_effectflags = false;
4340 return D_O_K;
4341 }
4342 int32_t onShowLayerE()
4343 {
4344 show_effectflags=!show_effectflags;
4345 if(show_effectflags)
4346 show_walkflags = false;
4347 return D_O_K;
4348 }
4349 int32_t onShowFFScripts()
4350 {
4351 show_ff_scripts=!show_ff_scripts;
4352 return D_O_K;
4353 }
4354 int32_t onShowHitboxes()
4355 {
4356 show_hitboxes=!show_hitboxes;
4357 return D_O_K;
4358 }
4359 int32_t onShowInfoOpacity()
4360 {
4361 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4362 zc_set_config("zc","debug_info_opacity",info_opacity);
4363 return D_O_K;
4364 }
4365
4366 int32_t onLightSwitch()
4367 {
4368 cheats_enqueue(Cheat::Light);
4369 return D_O_K;
4370 }
4371
4372 int32_t onGoTo();
4373 int32_t onGoToComplete();
4374
4375 9286090 bool handle_close_btn_quit()
4376 {
4377
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(close_button_quit)
4378 {
4379 close_button_quit=false;
4380 f_Quit(qEXIT);
4381 }
4382 9286090 return (exiting_program = Quit==qEXIT);
4383 }
4384
4385 9286090 void syskeys()
4386 {
4387 9286090 update_system_keys();
4388
4389 int32_t oldtitle_version;
4390
4391 9286090 poll_joystick();
4392
4393 9286090 handle_close_btn_quit();
4394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
9286090 if(Quit == qEXIT) return;
4395
4396
2/10
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9286090 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
9286090 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4397 {
4398 System();
4399 }
4400
4401 9286090 mouse_down=gui_mouse_b();
4402
4403
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(zc_read_system_key(KEY_F1))
4404 {
4405 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4406 {
4407 halt=!halt;
4408 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4409 }
4410 else
4411 {
4412 Throttlefps=!Throttlefps;
4413 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4414 }
4415 }
4416
4417 // if(zc_readkey(KEY_F1)) Vsync=!Vsync;
4418 /*
4419 if(zc_readkey(KEY_F1)) set_bit(QHeader.rules4,qr4_NEWENEMYTILES,
4420 1-((get_bit(QHeader.rules4,qr4_NEWENEMYTILES))));
4421 */
4422
4423
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(zc_read_system_key(KEY_F2))
4424 {
4425 ShowFPS=!ShowFPS;
4426 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4427 }
4428
4429
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286090 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4430
4431
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286090 if(zc_read_system_key(KEY_F4) && Playing)
4432 {
4433 Paused=true;
4434 Advance=true;
4435 }
4436
4437
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(zc_read_system_key(KEY_F6)) onTryQuit();
4438
4439 #ifndef ALLEGRO_MACOSX
4440
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4441
4442
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4443 #else
4444 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4445
4446 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4447 #endif
4448
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9286090 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4449
4450
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if (zc_read_system_key(KEY_F12))
4451 {
4452 onSnapshot();
4453 }
4454
4455
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286090 if(debug_enabled && zc_read_system_key(KEY_TAB))
4456 set_debug(!get_debug());
4457
4458
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(CheatModifierKeys())
4459 {
4460 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4461 {
4462 if(!bindable_cheat(c))
4463 continue;
4464 if(get_debug() || cheat >= cheat_lvl(c))
4465 {
4466 if(checkcheat(c))
4467 cheats_hit_bind(c);
4468 }
4469 }
4470 }
4471
4472
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(volkeys)
4473 {
4474 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4475
4476 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4477
4478 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4479
4480 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4481 }
4482
4483
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9286090 if(!get_debug() || !SystemKeys || replay_is_replaying())
4484 9286090 goto bottom;
4485
4486 if(zc_readkey(KEY_D))
4487 {
4488 details = !details;
4489 rectfill(screen,0,0,319,7,BLACK);
4490 rectfill(screen,0,8,31,239,BLACK);
4491 rectfill(screen,288,8,319,239,BLACK);
4492 rectfill(screen,32,232,287,239,BLACK);
4493 }
4494
4495 if(zc_readkey(KEY_P)) Paused=!Paused;
4496
4497 //if(zc_readkey(KEY_P)) centerHero();
4498 if(zc_readkey(KEY_A))
4499 {
4500 Paused=true;
4501 Advance=true;
4502 }
4503
4504 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4505 #ifndef ALLEGRO_MACOSX
4506 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4507
4508 if(zc_readkey(KEY_F7))
4509 {
4510 Matrix(ss_speed, ss_density, 0);
4511 game_pal();
4512 }
4513 #else
4514 // The reason these are different on Mac in the first place is that
4515 // the OS doesn't let us use F9 and F10...
4516 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4517
4518 if(zc_readkey(KEY_F9))
4519 {
4520 Matrix(ss_speed, ss_density, 0);
4521 game_pal();
4522 }
4523 #endif
4524 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4525 {
4526 //change containers
4527 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4528 {
4529 //magic containers
4530 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4531 {
4532 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4533 }
4534 else
4535 {
4536 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4537 }
4538 }
4539 else
4540 {
4541 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4542 {
4543 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4544 }
4545 else
4546 {
4547 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4548 }
4549 }
4550 }
4551
4552 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4553 {
4554 //change containers
4555 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4556 {
4557 //magic containers
4558 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4559 {
4560 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4561 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4562 //heart containers
4563 }
4564 else
4565 {
4566 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4567 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4568 }
4569 }
4570 else
4571 {
4572 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4573 {
4574 game->set_magic(zc_max(game->get_magic()-1,0));
4575 }
4576 else
4577 {
4578 game->set_life(zc_max(game->get_life()-1,0));
4579 }
4580 }
4581 }
4582
4583 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4584
4585 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4586
4587 verifyBothWeapons();
4588
4589 bottom:
4590
4591
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(input_idle(true) > after_time())
4592 {
4593 Matrix(ss_speed, ss_density, 0);
4594 game_pal();
4595 }
4596 9286090 }
4597
4598 705783 void checkQuitKeys()
4599 {
4600 #ifndef ALLEGRO_MACOSX
4601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 705783 times.
705783 if(key[KEY_F9]) f_Quit(qRESET);
4602
4603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 705783 times.
705783 if(key[KEY_F10]) f_Quit(qEXIT);
4604 #else
4605 if(key[KEY_F7]) f_Quit(qRESET);
4606
4607 if(key[KEY_F8]) f_Quit(qEXIT);
4608 #endif
4609 705783 }
4610
4611 9286090 bool CheatModifierKeys()
4612 {
4613 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4614 // to trigger cheats.
4615
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if (replay_is_replaying())
4616 9286090 return false;
4617
4618 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4619 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4620 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4621 {
4622 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4623 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4624 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4625 {
4626 return true;
4627 }
4628 }
4629 return false;
4630 9286090 }
4631
4632 //99:05:54, for some reason?
4633 #define OLDMAXTIME 21405240
4634 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4635 #define MAXTIME 1944000000
4636
4637 9286216 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4638 {
4639
1/2
✓ Branch 0 taken 9286216 times.
✗ Branch 1 not taken.
9286216 if(zcmusic!=NULL)
4640 {
4641 zcmusic_poll();
4642 }
4643 9286216 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4644
4645 9286216 updatescr(allowwavy);
4646
4647 9286216 Advance=false;
4648
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9286216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9286216 times.
9286216 while(Paused && !Advance && !Quit)
4649 {
4650 // have to call this, otherwise we'll get an infinite loop
4651 syskeys();
4652 if(allowF6Script)
4653 {
4654 FFCore.runF6Engine();
4655 }
4656 zc_throttle_fps();
4657
4658 #ifdef _WIN32
4659
4660 if(use_dwm_flush)
4661 {
4662 do_DwmFlush();
4663 }
4664
4665 #endif
4666
4667 // to keep music playing
4668 if(zcmusic!=NULL)
4669 {
4670 zcmusic_poll();
4671 }
4672
4673 update_hw_screen();
4674 }
4675
4676
2/2
✓ Branch 0 taken 9286104 times.
✓ Branch 1 taken 112 times.
9286216 if(Quit)
4677 112 return;
4678
4679
3/4
✓ Branch 0 taken 8984975 times.
✓ Branch 1 taken 301129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8984975 times.
9286104 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4680 8984975 game->change_time(1);
4681
4682 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4683
4684 9286104 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4685
2/2
✓ Branch 0 taken 20428 times.
✓ Branch 1 taken 9265676 times.
9286104 if (replay_version_check(0, 16))
4686 9265676 should_reset_down_state = replay_version_check(11, 16);
4687
2/2
✓ Branch 0 taken 6948559 times.
✓ Branch 1 taken 2337545 times.
9286104 if (should_reset_down_state)
4688 {
4689
2/2
✓ Branch 0 taken 42075810 times.
✓ Branch 1 taken 2337545 times.
44413355 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4690 42075810 down_control_states[i] = raw_control_state[i];
4691 2337545 }
4692
4693
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286090 times.
9286104 if (replay_is_active())
4694 {
4695
2/2
✓ Branch 0 taken 1270449 times.
✓ Branch 1 taken 8015641 times.
9286090 if (replay_version_check(3))
4696 8015641 replay_poll();
4697
4698
4/4
✓ Branch 0 taken 6944977 times.
✓ Branch 1 taken 2341113 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 6844442 times.
9286090 if (replay_version_check(11) || replay_version_check(6, 8))
4699 2441648 replay_peek_input();
4700 9286090 }
4701
4702 9286104 load_control_called_this_frame = false;
4703
4704 9286104 poll_keyboard();
4705 9286104 update_keys();
4706
4707 9286104 ++frame;
4708
4709
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286090 times.
9286104 if (replay_is_replaying())
4710 9286090 replay_do_cheats();
4711 9286104 syskeys();
4712
4713 // The mouse variables can change from the mouse thread at anytime during a frame,
4714 // so save the result at the start so that replaying is consistent.
4715 9286104 script_mouse_x = gui_mouse_x();
4716 9286104 script_mouse_y = gui_mouse_y();
4717 9286104 script_mouse_z = mouse_z;
4718 9286104 script_mouse_b = mouse_b;
4719
4720 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4721 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4722 // approach here means it doesn't matter which call adds the cheat.
4723 9286104 cheats_execute_queued();
4724
4725
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286090 times.
9286104 if (replay_is_replaying())
4726 9286090 replay_peek_quit();
4727
2/2
✓ Branch 0 taken 9286090 times.
✓ Branch 1 taken 14 times.
9286104 if (GameFlags & GAMEFLAG_TRYQUIT)
4728 14 replay_step_quit(0);
4729
2/2
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 9283170 times.
9286104 if(allowF6Script)
4730 9283170 FFCore.runF6Engine();
4731
2/2
✓ Branch 0 taken 299 times.
✓ Branch 1 taken 9285805 times.
9286104 if (Quit)
4732 299 replay_step_quit(Quit);
4733 // Someday... maybe install a Turbo button here?
4734 9286104 zc_throttle_fps();
4735
4736 #ifdef _WIN32
4737
4738 if(use_dwm_flush)
4739 {
4740 do_DwmFlush();
4741 }
4742
4743 #endif
4744
4745 //textprintf_ex(screen,font,0,72,254,BLACK,"%d %d", lastentrance, lastentrance_dmap);
4746
2/2
✓ Branch 0 taken 68758 times.
✓ Branch 1 taken 9217346 times.
9286104 if(sfxcleanup)
4747 9217346 sfx_cleanup();
4748
4749 9286104 jit_poll();
4750
4751 #ifdef __EMSCRIPTEN__
4752 // Yield the main thread back to the browser occasionally.
4753 if (is_headless())
4754 {
4755 static int rate = 10000;
4756 static int force_yield = rate;
4757 if (force_yield++ >= rate)
4758 {
4759 force_yield = 0;
4760 emscripten_sleep(0);
4761 }
4762 }
4763 #endif
4764
4765
4/6
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 9285989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 115 times.
✓ Branch 4 taken 115 times.
✗ Branch 5 not taken.
9286104 static bool test_mode_auto_restart = zc_get_config("zeldadx", "test_mode_auto_restart", false);
4766
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286104 if (zqtesting_mode && test_mode_auto_restart)
4767 {
4768 static auto last_write_time = fs::last_write_time(qstpath);
4769 static auto last_check = std::chrono::system_clock::now();
4770
4771 if (std::chrono::system_clock::now() - last_check > 200ms)
4772 {
4773 last_check = std::chrono::system_clock::now();
4774 auto write_time = fs::last_write_time(qstpath);
4775 if (last_write_time != write_time)
4776 {
4777 last_write_time = write_time;
4778 disableClickToFreeze = false;
4779 Quit = qRESET;
4780 replay_quit();
4781 }
4782 }
4783 }
4784 9286216 }
4785
4786 101 void zapout()
4787 {
4788 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4789 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4790
4791 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4792 101 script_drawing_commands.Clear();
4793
4794 // zap out
4795
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=1; i<=24; i++)
4796 {
4797 2424 draw_fuzzy(i);
4798 2424 advanceframe(true);
4799
4800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4801 {
4802 break;
4803 }
4804 2424 }
4805 101 }
4806
4807 101 void zapin()
4808 {
4809 101 FFCore.warpScriptCheck();
4810 101 draw_screen(tmpscr);
4811 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4812 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4813 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4814
4815 // zap out
4816 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4817
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=24; i>=1; i--)
4818 {
4819 2424 draw_fuzzy(i);
4820 2424 advanceframe(true);
4821
4822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4823 {
4824 break;
4825 }
4826 2424 }
4827 101 }
4828
4829
4830 65 void wavyout(bool showhero)
4831 {
4832 65 draw_screen(tmpscr, showhero);
4833 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4834
4835 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4836 65 clear_to_color(wavebuf,0);
4837 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4838
4839 static PALETTE wavepal;
4840
4841 int32_t ofs;
4842 65 int32_t amplitude=8;
4843
4844 65 int32_t wavelength=4;
4845 65 double palpos=0, palstep=4, palstop=126;
4846
4847 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4848
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4849 {
4850
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4851 {
4852 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4853 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4854 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4855 698880 }
4856
4857 2730 palpos+=palstep;
4858
4859
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4860 {
4861 2730 hw_palette = &wavepal;
4862 2730 update_hw_pal = true;
4863 2730 }
4864 else
4865 {
4866 hw_palette = &RAMpal;
4867 update_hw_pal = true;
4868 }
4869
4870
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4871 {
4872
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4873 {
4874 117411840 ofs=0;
4875
4876
4/4
✓ Branch 0 taken 57308160 times.
✓ Branch 1 taken 60103680 times.
✓ Branch 2 taken 28654080 times.
✓ Branch 3 taken 28654080 times.
117411840 if((j<i)&&(j&1))
4877 {
4878 28654080 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4879 28654080 }
4880
4881 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4882 117411840 }
4883 458640 }
4884
4885 2730 advanceframe(true);
4886
4887 // animate_combos();
4888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4889 break;
4890 2730 }
4891
4892 65 destroy_bitmap(wavebuf);
4893 65 }
4894
4895 65 void wavyin()
4896 {
4897 65 draw_screen(tmpscr);
4898 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4899
4900 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4901 65 clear_to_color(wavebuf,0);
4902 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4903
4904 static PALETTE wavepal;
4905
4906 //Breaks dark rooms.
4907 //In any case I don't think we need this, since palette is already loaded in doWarp() (famous last words...) -DD
4908 /*
4909 loadfullpal();
4910 loadlvlpal(DMaps[currdmap].color);
4911 ringcolor(false);
4912 */
4913 65 refreshpal=false;
4914 int32_t ofs;
4915 65 int32_t amplitude=8;
4916 65 int32_t wavelength=4;
4917 65 double palpos=168, palstep=4, palstop=126;
4918
4919 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4920
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4921 {
4922
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4923 {
4924 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4925 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4926 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4927 698880 }
4928
4929 2730 palpos-=palstep;
4930
4931
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4932 {
4933 2730 hw_palette = &wavepal;
4934 2730 update_hw_pal = true;
4935 2730 }
4936 else
4937 {
4938 hw_palette = &RAMpal;
4939 update_hw_pal = true;
4940 }
4941
4942
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4943 {
4944
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4945 {
4946 117411840 ofs=0;
4947
4948
4/4
✓ Branch 0 taken 59404800 times.
✓ Branch 1 taken 58007040 times.
✓ Branch 2 taken 30051840 times.
✓ Branch 3 taken 29352960 times.
117411840 if((j<(167-i))&&(j&1))
4949 {
4950 29352960 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4951 29352960 }
4952
4953 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4954 117411840 }
4955 458640 }
4956
4957 2730 advanceframe(true);
4958 // animate_combos();
4959
4960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4961 break;
4962 2730 }
4963
4964 65 destroy_bitmap(wavebuf);
4965 65 }
4966
4967 2168 void blackscr(int32_t fcnt,bool showsubscr)
4968 {
4969 2168 reset_pal_cycling();
4970 2168 script_drawing_commands.Clear();
4971
4972 2168 FFCore.warpScriptCheck();
4973 2168 bool showtime = game->should_show_time();
4974
2/2
✓ Branch 0 taken 2168 times.
✓ Branch 1 taken 64970 times.
67138 while(fcnt>0)
4975 {
4976 64970 clear_bitmap(framebuf);
4977
4978
2/2
✓ Branch 0 taken 25080 times.
✓ Branch 1 taken 39890 times.
64970 if(showsubscr)
4979 {
4980 39890 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4981
3/4
✓ Branch 0 taken 39890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 750 times.
✓ Branch 3 taken 39140 times.
39890 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4982 {
4983 750 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4984 750 }
4985 39890 }
4986
4987 64970 advanceframe(true);
4988
4989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64970 times.
64970 if(Quit)
4990 break;
4991
4992 64970 --fcnt;
4993 }
4994 2168 }
4995
4996 1011 void openscreen(int32_t shape)
4997 {
4998 1011 reset_pal_cycling();
4999 1011 black_opening_count=0;
5000
5001
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 911 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
1011 if(COOLSCROLL || shape>-1)
5002 {
5003 911 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5004 911 return;
5005 }
5006 else
5007 {
5008 100 Hero.setDontDraw(true);
5009 100 show_subscreen_dmap_dots=false;
5010 100 show_subscreen_numbers=false;
5011 // show_subscreen_items=false;
5012 100 show_subscreen_life=false;
5013 }
5014
5015 100 int32_t x=128;
5016
5017 100 FFCore.warpScriptCheck();
5018
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 8000 times.
8100 for(int32_t i=0; i<80; i++)
5019 {
5020 8000 draw_screen(tmpscr);
5021 //? draw_screen already draws the subscreen -DD
5022 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5023 8000 x=128-(((i*128/80)/8)*8);
5024
5025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(x>0)
5026 {
5027 8000 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5028 8000 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5029 8000 }
5030
5031 8000 advanceframe(true);
5032
5033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(Quit)
5034 {
5035 break;
5036 }
5037 8000 }
5038
5039 100 Hero.setDontDraw(false);
5040 100 show_subscreen_items=true;
5041 100 show_subscreen_dmap_dots=true;
5042 1011 }
5043
5044 void closescreen(int32_t shape)
5045 {
5046 reset_pal_cycling();
5047 black_opening_count=0;
5048
5049 if(COOLSCROLL || shape>-1)
5050 {
5051 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5052 return;
5053 }
5054 else
5055 {
5056 Hero.setDontDraw(true);
5057 show_subscreen_dmap_dots=false;
5058 show_subscreen_numbers=false;
5059 // show_subscreen_items=false;
5060 show_subscreen_life=false;
5061 }
5062
5063 int32_t x=128;
5064
5065 FFCore.warpScriptCheck();
5066 for(int32_t i=79; i>=0; --i)
5067 {
5068 draw_screen(tmpscr);
5069 //? draw_screen already draws the subscreen -DD
5070 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5071 x=128-(((i*128/80)/8)*8);
5072
5073 if(x>0)
5074 {
5075 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5076 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5077 }
5078
5079 advanceframe(true);
5080
5081 if(Quit)
5082 {
5083 break;
5084 }
5085 }
5086
5087 Hero.setDontDraw(false);
5088 show_subscreen_items=true;
5089 show_subscreen_dmap_dots=true;
5090 }
5091
5092 179 int32_t TriforceCount()
5093 {
5094 179 int32_t c=0;
5095
5096
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 179 times.
1611 for(int32_t i=1; i<=8; i++)
5097
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 1044 times.
2476 if(game->lvlitems[i]&liTRIFORCE)
5098 1044 ++c;
5099
5100 179 return c;
5101 }
5102
5103 int32_t onCustomGame()
5104 {
5105 int32_t file = getsaveslot();
5106
5107 if(file < 0)
5108 return D_O_K;
5109
5110 bool ret = (custom_game(file)!=0);
5111 return ret ? D_CLOSE : D_O_K;
5112 }
5113
5114 int32_t onContinue()
5115 {
5116 return D_CLOSE;
5117 }
5118
5119 int32_t onEsc() // Unused?? -L
5120 {
5121 return zc_getrawkey(KEY_ESC, true)?D_CLOSE:D_O_K;
5122 }
5123
5124 int32_t onVsync()
5125 {
5126 Throttlefps = !Throttlefps;
5127 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
5128 return D_O_K;
5129 }
5130
5131 int32_t onWinPosSave()
5132 {
5133 SaveWinPos = !SaveWinPos;
5134 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
5135 return D_O_K;
5136 }
5137 int32_t onIntegerScaling()
5138 {
5139 scaleForceInteger = !scaleForceInteger;
5140 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
5141 return D_O_K;
5142 }
5143 int32_t onStretchGame()
5144 {
5145 stretchGame = !stretchGame;
5146 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
5147 return D_O_K;
5148 }
5149
5150 int32_t onClickToFreeze()
5151 {
5152 ClickToFreeze = !ClickToFreeze;
5153 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
5154 return D_O_K;
5155 }
5156
5157 int32_t OnSaveZCConfig()
5158 {
5159 if(jwin_alert3(
5160 "Save Configuration",
5161 "Are you sure that you wish to save your present configuration settings?",
5162 "This will overwrite your prior settings!",
5163 NULL,
5164 "&Yes",
5165 "&No",
5166 NULL,
5167 'y',
5168 'n',
5169 0,
5170 get_zc_font(font_lfont)) == 1)
5171 {
5172 save_game_configs();
5173 return D_O_K;
5174 }
5175 else return D_O_K;
5176 }
5177
5178 int32_t OnnClearQuestDir()
5179 {
5180 auto current_path = fs::current_path() / "quests";
5181 if(jwin_alert3(
5182 "Clear Current Directory Cache",
5183 "Are you sure that you wish to reset where ZC Player looks for quests?",
5184 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
5185 NULL,
5186 "&Yes",
5187 "&No",
5188 NULL,
5189 'y',
5190 'n',
5191 0,
5192 get_zc_font(font_lfont)) == 1)
5193 {
5194 zc_set_config("zeldadx","quest_dir","quests");
5195 flush_config_file();
5196 strcpy(qstdir,"quests");
5197 #ifdef __EMSCRIPTEN__
5198 em_sync_fs();
5199 #endif
5200 return D_O_K;
5201 }
5202 else return D_O_K;
5203 }
5204
5205
5206 int32_t onConsoleZASM()
5207 {
5208 if ( !zasm_debugger )
5209 {
5210 AlertDialog("WARNING: ZASM Debugger",
5211 "Enabling this will open the ZASM Debugger Console"
5212 "\nThis will likely grind ZC to a halt with lag."
5213 "\nTo make any use of this, it is suggested that you read"
5214 "\nthe documentation for 'void Breakpoint(char[] string);'"
5215 " in 'ZScript_Additions.txt'"
5216 "\nThis is not recommended for normal users,"
5217 " and is only intended for ZC developers,"
5218 "\nor quest developers coding directly in ZASM"
5219 "\nAre you sure that you wish to open the ZASM Debugger?",
5220 [&](bool ret,bool)
5221 {
5222 if(ret)
5223 {
5224 FFCore.ZASMPrint(true);
5225 }
5226 }).show();
5227 return D_O_K;
5228 }
5229 else
5230 {
5231 FFCore.ZASMPrint(false);
5232 return D_O_K;
5233 }
5234 }
5235
5236
5237 int32_t onConsoleZScript()
5238 {
5239 if ( !zscript_debugger )
5240 {
5241 AlertDialog("ZScript Debugger",
5242 "Enabling this will open the ZScript Debugger Console"
5243 "\nThis will display any messages logged by scripts,"
5244 " including script errors."
5245 "\nAre you sure that you wish to open the ZScript Debugger?",
5246 [&](bool ret,bool)
5247 {
5248 if(ret)
5249 {
5250 FFCore.ZScriptConsole(true);
5251 }
5252 }).show();
5253 return D_O_K;
5254 }
5255 else
5256 {
5257 FFCore.ZScriptConsole(false);
5258 return D_O_K;
5259 }
5260 }
5261
5262 int32_t onClrConsoleOnReload()
5263 {
5264 clearConsoleOnReload = !clearConsoleOnReload;
5265 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5266 return D_O_K;
5267 }
5268 int32_t onClrConsoleOnLoad()
5269 {
5270 clearConsoleOnLoad = !clearConsoleOnLoad;
5271 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5272 return D_O_K;
5273 }
5274
5275
5276 int32_t onFrameSkip()
5277 {
5278 FrameSkip = !FrameSkip;
5279 return D_O_K;
5280 }
5281
5282 int32_t onSaveDragResize()
5283 {
5284 SaveDragResize = !SaveDragResize;
5285 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5286 return D_O_K;
5287 }
5288
5289 int32_t onDragAspect()
5290 {
5291 DragAspect = !DragAspect;
5292 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5293 return D_O_K;
5294 }
5295
5296 int32_t onTransLayers()
5297 {
5298 TransLayers = !TransLayers;
5299 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5300 return D_O_K;
5301 }
5302
5303 int32_t onNESquit()
5304 {
5305 NESquit = !NESquit;
5306 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5307 return D_O_K;
5308 }
5309
5310 int32_t onVolKeys()
5311 {
5312 volkeys = !volkeys;
5313 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5314 return D_O_K;
5315 }
5316
5317 int32_t onShowFPS()
5318 {
5319 ShowFPS = !ShowFPS;
5320 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5321 return D_O_K;
5322 }
5323
5324 1095758620 bool is_Fkey(int32_t k)
5325 {
5326
2/2
✓ Branch 0 taken 111433080 times.
✓ Branch 1 taken 984325540 times.
1095758620 switch(k)
5327 {
5328 case KEY_F1:
5329 case KEY_F2:
5330 case KEY_F3:
5331 case KEY_F4:
5332 case KEY_F5:
5333 case KEY_F6:
5334 case KEY_F7:
5335 case KEY_F8:
5336 case KEY_F9:
5337 case KEY_F10:
5338 case KEY_F11:
5339 case KEY_F12:
5340 111433080 return true;
5341 }
5342
5343 984325540 return false;
5344 1095758620 }
5345
5346 void kb_getkey(DIALOG *d);
5347
5348 //Used by all keyboard key settings dialogues.
5349 void kb_clearjoystick(DIALOG *d)
5350 {
5351 d->flags|=D_SELECTED;
5352
5353 jwin_button_proc(MSG_DRAW,d,0);
5354 jwin_draw_win(gui_bmp, (gui_bmp->w-160)/2, (gui_bmp->h-48)/2, 168, 48, FR_WIN);
5355 // text_mode(vc(11));
5356 textout_centre_ex(gui_bmp, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5357 textout_centre_ex(gui_bmp, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5358
5359 update_hw_screen(true);
5360
5361 clear_keybuf();
5362 int32_t k = next_press_key();
5363 clear_keybuf();
5364
5365 //shnarf
5366 //47=f1
5367 //59=esc
5368 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5369 // *((int32_t*)d->dp3) = k;
5370 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5371
5372
5373 d->flags&=~D_SELECTED;
5374 }
5375
5376 //Clears key to 0.
5377 //Used by all keyboard key settings dialogues.
5378 void kb_clearkey(DIALOG *d);
5379
5380 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5381 {
5382 switch(msg)
5383 {
5384 case MSG_KEY:
5385 case MSG_CLICK:
5386
5387 kb_clearjoystick(d);
5388
5389 while(gui_mouse_b())
5390 {
5391 clear_keybuf();
5392 rest(1);
5393 }
5394
5395 return D_REDRAW;
5396 }
5397
5398 return jwin_button_proc(msg,d,c);
5399 }
5400
5401 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5402 //Only used in keyboard settings dialogues to clear keys.
5403 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5404
5405 int32_t j_getbtn(DIALOG *d)
5406 {
5407 d->flags|=D_SELECTED;
5408 jwin_button_proc(MSG_DRAW,d,0);
5409 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5410 // text_mode(vc(11));
5411 int32_t y = screen->h/2 - 12;
5412 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5413 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5414 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5415
5416 update_hw_screen(true);
5417
5418 int32_t b = next_joy_input(true);
5419 if (b == -2)
5420 return D_CLOSE;
5421
5422 if(b>=0)
5423 *((int32_t*)d->dp3) = b;
5424
5425 d->flags&=~D_SELECTED;
5426
5427 if (player)
5428 player->joy_on = TRUE;
5429
5430 return D_O_K;
5431 }
5432
5433 void j_getstick(DIALOG *d)
5434 {
5435 d->flags|=D_SELECTED;
5436 jwin_button_proc(MSG_DRAW,d,0);
5437 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5438 // text_mode(vc(11));
5439 int32_t y = screen->h/2 - 12;
5440 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5441 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5442 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5443
5444 update_hw_screen(true);
5445
5446 int32_t b = next_joy_input(false);
5447
5448 if(b>=0)
5449 *((int32_t*)d->dp3) = b;
5450
5451 d->flags&=~D_SELECTED;
5452
5453 if (player)
5454 player->joy_on = TRUE;
5455 }
5456
5457 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5458 {
5459 switch(msg)
5460 {
5461 case MSG_KEY:
5462 case MSG_CLICK:
5463
5464 int ret = j_getbtn(d);
5465 if (ret != D_O_K)
5466 return ret;
5467
5468 while(gui_mouse_b()) {
5469 rest(1);
5470 clear_keybuf();
5471 }
5472
5473 return D_REDRAW;
5474 }
5475
5476 return jwin_button_proc(msg,d,c);
5477 }
5478
5479 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5480 {
5481 switch(msg)
5482 {
5483 case MSG_KEY:
5484 case MSG_CLICK:
5485
5486 j_getstick(d);
5487
5488 while(gui_mouse_b()) {
5489 rest(1);
5490 clear_keybuf();
5491 }
5492
5493 return D_REDRAW;
5494 }
5495
5496 return jwin_button_proc(msg,d,c);
5497 }
5498
5499 //shnarf
5500 extern const char *key_str[];
5501 std::string get_keystr(int key);
5502
5503 const char *pan_str[4] = { "MONO", " 1/2", " 3/4", "FULL" };
5504 //extern int32_t zcmusic_bufsz;
5505
5506 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5507 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5508 str_primary_stick[80], str_secondary_stick[80];
5509
5510 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5511 {
5512 //these are here to bypass compiler warnings about unused arguments
5513 c=c;
5514
5515 if (d->w == 1)
5516 {
5517 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5518 {
5519 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5520 return D_CLOSE;
5521 }
5522 }
5523
5524 if(msg==MSG_DRAW)
5525 {
5526 switch(d->w)
5527 {
5528 case 0:
5529 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5530 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5531 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5532 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5533 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5534 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5535 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5536 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5537 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5538 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5539 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5540 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5541 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5542 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5543 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5544 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5545 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5546 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5547 break;
5548
5549 case 1:
5550 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5551 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5552 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5553 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5554 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5555 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5556 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5557 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5558 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5559 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5560 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5561 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5562 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5563 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5564 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5565 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5566 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5567 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5568 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5569 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5570 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5571 break;
5572
5573 case 2:
5574 sprintf(str_a," %3d",midi_volume);
5575 sprintf(str_b," %3d",digi_volume);
5576 sprintf(str_l," %3d",emusic_volume);
5577 sprintf(str_m," %3dKB",zcmusic_bufsz);
5578 sprintf(str_r," %3d",sfx_volume);
5579 strcpy(str_s,pan_str[pan_style]);
5580 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5581 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5582 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5583 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5584 break;
5585 }
5586 }
5587
5588 return D_O_K;
5589 }
5590
5591 int32_t set_vol(void *dp3, int32_t d2)
5592 {
5593 switch(((int32_t*)dp3)[0])
5594 {
5595 case 0:
5596 midi_volume = zc_min(d2<<3,255);
5597 break;
5598
5599 case 1:
5600 digi_volume = zc_min(d2<<3,255);
5601 break;
5602
5603 case 2:
5604 emusic_volume = zc_min(d2<<3,255);
5605 break;
5606
5607 case 3:
5608 sfx_volume = zc_min(d2<<3,255);
5609 break;
5610 }
5611
5612 // text_mode(vc(11));
5613 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3d",zc_min(d2<<3,255));
5614 return D_O_K;
5615 }
5616
5617 int32_t set_pan(void *dp3, int32_t d2)
5618 {
5619 pan_style = vbound(d2,0,3);
5620 // text_mode(vc(11));
5621 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5622 return D_O_K;
5623 }
5624
5625 int32_t set_buf(void *dp3, int32_t d2)
5626 {
5627 // text_mode(vc(11));
5628 zcmusic_bufsz = d2 + 1;
5629 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3dKB",zcmusic_bufsz);
5630 return D_O_K;
5631 }
5632
5633 static int32_t gamepad_joys_list[] =
5634 {
5635 61,
5636 -1
5637 };
5638
5639 static int32_t gamepad_btn_list[] =
5640 {
5641 6,
5642 7,8,9,10,11,12,13,14,15,16,17,
5643 18,19,20,21,22,23,24,25,26,27,28,
5644 29,30,31,32,33,34,35,36,37,38,39,
5645 -1
5646 };
5647
5648 static int32_t gamepad_dirs_list[] =
5649 {
5650 40,41,42,43,
5651 44,45,46,47,
5652 48,49,50,51,
5653 52,53,54,55,
5654 56,57,58,59,
5655 60,
5656 -1
5657 };
5658
5659 static TABPANEL gamepad_tabs[] =
5660 {
5661 // (text)
5662 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5663 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5664 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5665 { NULL, 0, NULL, 0, NULL }
5666 };
5667
5668 const char *joy_list(int32_t index, int32_t *list_size)
5669 {
5670 if (index == -1)
5671 {
5672 *list_size = al_get_num_joysticks();
5673 return NULL;
5674 }
5675
5676 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5677 if (!joy)
5678 {
5679 return "?";
5680 }
5681
5682 return al_get_joystick_name(joy);
5683 }
5684
5685 115 static ListData joy__list(joy_list, &font);
5686
5687 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5688 {
5689 int32_t d2 = d->d2;
5690 int32_t ret = jwin_droplist_proc(msg,d,c);
5691
5692 if(d2!=d->d2)
5693 {
5694 joystick_index = d->d2;
5695 ret |= D_REDRAW_ALL;
5696 }
5697
5698 return ret;
5699 }
5700
5701 static DIALOG gamepad_dlg[] =
5702 {
5703 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5704 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5705 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5706 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5708 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5709 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5710 // 6
5711 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5712 // 7
5713 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5714 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5715 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5716 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5717 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5718 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5719 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5720 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5721 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5722 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5723 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5724 // 18
5725 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5726 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5727 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5728 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5729 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5730 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5731 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5732 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5733 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5734 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5735 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5736 // 29
5737 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5738 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5739 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5740 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5741 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5742 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5743 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5744 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5745 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5746 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5747 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5748 // 40
5749 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5750 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5751 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5752 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5753 // 44
5754 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5755 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5756 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5757 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5758 // 48
5759 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5760 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5761 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5762 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5763 // 52
5764 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5765 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5766 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5767 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5768 // 56
5769 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5770 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5771 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5772 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5773 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5774
5775 // 61
5776 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5777
5778 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5779 };
5780
5781 static int32_t keyboard_keys_list[] =
5782 {
5783 6,7,8,9,10,
5784 11,12,13,14,15,16,17,18,19,20,
5785 21,22,23,24,25,26,27,28,29,30,
5786 31,32,33,34,35,36,37,38,39,40,
5787 -1
5788 };
5789
5790 static int32_t keyboard_dirs_list[] =
5791 {
5792 41,42,43,44,
5793 45,46,47,48,
5794 49,50,51,52,
5795 53,54,55,56,
5796 -1
5797 };
5798
5799 static int32_t keyboard_mods_list[] =
5800 {
5801 57,58,59,60,
5802 61,62,63,64,
5803 65,66,67,68,
5804 69,70,71,72,
5805 -1
5806 };
5807
5808 static TABPANEL keyboard_control_tabs[] =
5809 {
5810 // (text)
5811 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5812 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5813 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5814 { NULL, 0, NULL, 0, NULL }
5815 };
5816
5817 static DIALOG keyboard_control_dlg[] =
5818 {
5819 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5820 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5821 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5822 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5823 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5824 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5825 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5826 // Keys
5827 // 6
5828 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5829 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5830 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5831 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5832 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5833 // 11
5834 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5835 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5836 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5837 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5838 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5839 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5840 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5841 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5842 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5843 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5844 // 21
5845 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5846 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5847 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5848 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5849 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5850 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5851 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5852 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5853 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5854 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5855 // 31
5856 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5857 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5858 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5859 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5860 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5861 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5862 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5863 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5864 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5865 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5866 // Dirs
5867 // 41
5868 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5869 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5870 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5871 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5872 // 45
5873 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5874 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5875 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5876 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5877 // 49
5878 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5879 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5880 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5881 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5882 // 53
5883 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5884 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5885 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5886 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5887 // Mods
5888 // 57
5889 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5890 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5891 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5892 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5893 // 61
5894 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5895 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5896 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5897 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5898 // 65
5899 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5900 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5901 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5902 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5903 // 69
5904 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5905 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5906 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5907 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5908 // 73
5909 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5910 };
5911
5912 /*
5913 int32_t midi_dp[3] = {0,147,104};
5914 int32_t digi_dp[3] = {1,147,120};
5915 int32_t pan_dp[3] = {0,147,136};
5916 int32_t buf_dp[3] = {0,147,152};
5917 */
5918 int32_t midi_dp[3] = {0,0,0};
5919 int32_t digi_dp[3] = {1,0,0};
5920 int32_t emus_dp[3] = {2,0,0};
5921 int32_t buf_dp[3] = {0,0,0};
5922 int32_t sfx_dp[3] = {3,0,0};
5923 int32_t pan_dp[3] = {0,0,0};
5924
5925 static DIALOG sound_dlg[] =
5926 {
5927 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5928 115 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5929 115 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5930 115 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5931 115 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5932 115 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5933 115 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5934 115 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5935 115 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_b, NULL, NULL },
5936 115 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5937 115 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_m, NULL, NULL },
5938 // 10
5939 115 { jwin_rtext_proc, 190, 104, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5940 115 { jwin_rtext_proc, 190, 120, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5941 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5942 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5943 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5944 115 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5945 115 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, digi_dp },
5946 115 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5947 115 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 127, 0, NULL, (void *) set_buf, buf_dp },
5948 115 { jwin_slider_proc, 196, 104, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5949 //20
5950 115 { jwin_slider_proc, 196, 120, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5951 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5952 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5953 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5954 115 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master MIDI Volume", NULL, NULL },
5955 115 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master Digi Volume", NULL, NULL },
5956 115 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Volume", NULL, NULL },
5957 115 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Buffer", NULL, NULL },
5958 115 { jwin_text_proc, 17, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5959 115 { jwin_text_proc, 17, 120, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5960 //30
5961 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5962 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5963 115 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5964 115 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5965 };
5966
5967 char zc_builddate[80];
5968 char zc_aboutstr[80];
5969
5970 static DIALOG about_dlg[] =
5971 {
5972 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5973 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5974 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5975 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5976 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5977 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5978 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5979 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5980 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5981 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5982 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5983 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5984 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5985 };
5986
5987
5988 static DIALOG quest_dlg[] =
5989 {
5990 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5991 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5992 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5993 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5994 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5995 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5996 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5997 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5998 { jwin_text_proc, 184, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5999 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
6000 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
6001 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
6002 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
6003 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
6004 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6005 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6006 };
6007
6008 static DIALOG triforce_dlg[] =
6009 {
6010 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6011 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
6012 // 1
6013 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
6014 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
6015 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
6016 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
6017 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
6018 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
6019 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
6020 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
6021 // 9
6022 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6023 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6024 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6025 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6026 };
6027
6028 bool zc_getname(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6029 {
6030 go();
6031 int32_t ret=0;
6032 ret = zc_getname_nogo(prompt,ext,list,def,usefilename);
6033 comeback();
6034 return ret != 0;
6035 }
6036
6037
6038 bool zc_getname_nogo(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6039 {
6040 if(def!=modulepath)
6041 strcpy(modulepath,def);
6042
6043 if(!usefilename)
6044 {
6045 int32_t i=(int32_t)strlen(modulepath);
6046
6047 while(i>=0 && modulepath[i]!='\\' && modulepath[i]!='/')
6048 modulepath[i--]=0;
6049 }
6050
6051 // int32_t ret = file_select_ex(prompt,modulepath,ext,255,-1,-1);
6052 int32_t ret=0;
6053 int32_t sel=0;
6054
6055 if(list==NULL)
6056 {
6057 ret = jwin_file_select_ex(prompt,modulepath,ext,2048,-1,-1,get_zc_font(font_lfont));
6058 }
6059 else
6060 {
6061 ret = jwin_file_browse_ex(prompt, modulepath, list, &sel, 2048, -1, -1, get_zc_font(font_lfont));
6062 }
6063
6064 return ret!=0;
6065 }
6066
6067 int32_t onToggleRecordingNewSaves()
6068 {
6069 if (zc_get_config("zeldadx", "replay_new_saves", false))
6070 {
6071 zc_set_config("zeldadx", "replay_new_saves", false);
6072 }
6073 else
6074 {
6075 zc_set_config("zeldadx", "replay_new_saves", true);
6076 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
6077 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6078 }
6079 return D_O_K;
6080 }
6081
6082 int32_t onToggleSnapshotAllFrames()
6083 {
6084 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
6085 return D_O_K;
6086 }
6087
6088 int32_t onStopReplayOrRecord()
6089 {
6090 if (replay_is_replaying())
6091 {
6092 replay_quit();
6093 }
6094 else if (replay_get_mode() == ReplayMode::Record)
6095 {
6096 if (!replay_get_meta_bool("test_mode"))
6097 {
6098 jwin_alert("Recording", "You cannot stop recording a save file.",
6099 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6100 return D_CLOSE;
6101 }
6102
6103 if (jwin_alert("Stop Recording",
6104 "Save replay to disk and stop recording?",
6105 "This will stop the recording.",
6106 NULL,
6107 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6108 return D_CLOSE;
6109
6110 replay_save();
6111 replay_stop();
6112 }
6113 return D_O_K;
6114 }
6115
6116 static int32_t handle_on_load_replay(ReplayMode mode)
6117 {
6118 if (Playing)
6119 {
6120 if (jwin_alert("Replay - Warning!",
6121 "Loading a replay will exit the current game.",
6122 "All unsaved progress will be lost.",
6123 "Do you wish to continue?",
6124 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6125 return D_CLOSE;
6126 }
6127
6128 std::string mode_string = replay_mode_to_string(mode);
6129 mode_string[0] = std::toupper(mode_string[0]);
6130
6131 std::string line_1 = "Select a replay file to play back.";
6132 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
6133 std::string line_3 = "You can stop the replay and take over manually any time.";
6134 if (mode == ReplayMode::Update)
6135 {
6136 line_1 = "Select a replay file to update.";
6137 line_2 = "WARNING: be sure to back up the zplay file";
6138 line_3 = "and verify that the updated replay works as expected!";
6139 }
6140
6141 if (jwin_alert(mode_string.c_str(),
6142 line_1.c_str(),
6143 line_2.c_str(),
6144 line_3.c_str(),
6145 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
6146 {
6147 char replay_path[2048];
6148 strcpy(replay_path, "replays/");
6149 if (jwin_file_select_ex(
6150 fmt::format("Load Replay ({})", REPLAY_EXTENSION).c_str(),
6151 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6152 return D_CLOSE;
6153
6154 replay_quit();
6155 load_replay_file_deferred(mode, replay_path);
6156 Quit = qRESET;
6157 return D_CLOSE;
6158 }
6159 return D_O_K;
6160 }
6161
6162 int32_t onLoadReplay()
6163 {
6164 return handle_on_load_replay(ReplayMode::Replay);
6165 }
6166
6167 int32_t onLoadReplayAssert()
6168 {
6169 return handle_on_load_replay(ReplayMode::Assert);
6170 }
6171
6172 int32_t onLoadReplayUpdate()
6173 {
6174 return handle_on_load_replay(ReplayMode::Update);
6175 }
6176
6177 int32_t onSaveReplay()
6178 {
6179 if (replay_get_mode() == ReplayMode::Record)
6180 {
6181 if (!replay_get_meta_bool("test_mode"))
6182 {
6183 if (jwin_alert("Save Replay",
6184 "This will save a copy of the replay up to this point.",
6185 "The official replay file will be untouched.",
6186 "Do you wish to continue?",
6187 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6188 return D_CLOSE;
6189
6190 char replay_path[2048];
6191 strcpy(replay_path, replay_get_replay_path().string().c_str());
6192 if (jwin_file_select_ex(
6193 fmt::format("Save Replay ({})", REPLAY_EXTENSION).c_str(),
6194 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6195 return D_CLOSE;
6196
6197 if (fileexists(replay_path))
6198 {
6199 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
6200 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6201 return D_CLOSE;
6202 }
6203
6204 replay_save(replay_path);
6205 }
6206 else
6207 {
6208 replay_save();
6209 }
6210 }
6211 return D_O_K;
6212 }
6213
6214 static MENU replay_menu[] =
6215 {
6216 { (char *)"Record new saves", onToggleRecordingNewSaves, NULL, 0, NULL },
6217 { (char *)"Stop replay", onStopReplayOrRecord, NULL, 0, NULL },
6218 { (char *)"Load replay", onLoadReplay, NULL, 0, NULL },
6219 { (char *)"Load replay (assert)", onLoadReplayAssert, NULL, 0, NULL },
6220 { (char *)"Load replay (update)", onLoadReplayUpdate, NULL, 0, NULL },
6221 { (char *)"Save replay", onSaveReplay, NULL, 0, NULL },
6222 { (char *)"Enable snapshot all frames", onToggleSnapshotAllFrames,NULL, 0, NULL },
6223
6224 { NULL, NULL, NULL, 0, NULL }
6225 };
6226
6227 static DIALOG credits_dlg[] =
6228 {
6229 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6230 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6231 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6232 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6233 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6234 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6235 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6236 };
6237
6238 115 static ListData dmap_list(dmaplist, &font);
6239
6240 static DIALOG goto_dlg[] =
6241 {
6242 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6243 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6244 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6245 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6246 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6247 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6248 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6249 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6250 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6251 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6252 };
6253
6254 int32_t onGoTo()
6255 {
6256 bool music = false;
6257 music = music;
6258 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6259
6260 goto_dlg[0].dp2=get_zc_font(font_lfont);
6261 goto_dlg[4].d2=cheat_goto_dmap;
6262 goto_dlg[6].dp=cheat_goto_screen_str;
6263
6264 clear_keybuf();
6265
6266 large_dialog(goto_dlg);
6267
6268 if(do_zqdialog(goto_dlg,4)==1)
6269 {
6270 // dmap, screen
6271 cheats_enqueue(Cheat::GoTo, goto_dlg[4].d2, zc_min(zc_xtoi(cheat_goto_screen_str),0x7F));
6272 };
6273
6274 return D_O_K;
6275 }
6276
6277 int32_t onGoToComplete()
6278 {
6279 if(!Playing)
6280 {
6281 return D_O_K;
6282 }
6283
6284 enter_sys_pal();
6285 music_pause();
6286 pause_all_sfx();
6287 onGoTo();
6288 eat_buttons();
6289
6290 zc_readrawkey(KEY_ESC);
6291
6292 exit_sys_pal();
6293 music_resume();
6294 resume_all_sfx();
6295 return D_O_K;
6296 }
6297
6298 int32_t onCredits()
6299 {
6300 return D_O_K;
6301 }
6302
6303 const char *midilist(int32_t index, int32_t *list_size)
6304 {
6305 if(index<0)
6306 {
6307 *list_size=0;
6308
6309 for(int32_t i=0; i<MAXMIDIS; i++)
6310 if(tunes[i].data)
6311 ++(*list_size);
6312
6313 return NULL;
6314 }
6315
6316 int32_t i=0,m=0;
6317
6318 while(m<=index && i<=MAXMIDIS)
6319 {
6320 if(tunes[i].data)
6321 ++m;
6322
6323 ++i;
6324 }
6325
6326 --i;
6327
6328 if(i==MAXMIDIS && m<index)
6329 return "(null)";
6330
6331 return tunes[i].title;
6332 }
6333
6334 /* ------- MIDI info stuff -------- */
6335
6336 char *text;
6337 midi_info *zmi;
6338 bool dialog_running;
6339 bool listening;
6340
6341 void get_info(int32_t index);
6342
6343 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6344 {
6345 int32_t d2 = d->d2;
6346 int32_t ret = jwin_droplist_proc(msg,d,c);
6347
6348 if(d2!=d->d2)
6349 {
6350 get_info(d->d2);
6351 }
6352
6353 return ret;
6354 }
6355
6356 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6357 {
6358 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6359
6360 int32_t ret = jwin_button_proc(msg,d,c);
6361
6362 if(ret == D_CLOSE)
6363 {
6364 // get current midi index
6365 int32_t index = (d+(d->d1))->d2;
6366 int32_t i=0, m=0;
6367
6368 while(m<=index && i<=MAXMIDIS)
6369 {
6370 if(tunes[i].data)
6371 ++m;
6372
6373 ++i;
6374 }
6375
6376 --i;
6377 jukebox(i);
6378 listening = true;
6379 ret = D_O_K;
6380 }
6381
6382 return ret;
6383 }
6384
6385 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6386 {
6387 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6388
6389 int32_t ret = jwin_button_proc(msg,d,c);
6390
6391 if(ret == D_CLOSE)
6392 {
6393 // get current midi index
6394 int32_t index = (d+(d->d1))->d2;
6395 int32_t i=0, m=0;
6396
6397 while(m<=index && i<=MAXMIDIS)
6398 {
6399 if(tunes[i].data)
6400 ++m;
6401
6402 ++i;
6403 }
6404
6405 --i;
6406
6407 // get file name
6408
6409 int32_t sel=0;
6410 //struct ffblk f;
6411 char title[40] = "Save MIDI: ";
6412 char fname[2048];
6413 memset(fname,0,2048);
6414 static EXT_LIST list[] =
6415 {
6416 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6417 { (char *)"HTML files (*.html, *.html)", (char *)"htm html" },
6418 { NULL, NULL }
6419 };
6420
6421 strcpy(title+11, tunes[i].title);
6422 title[39] = '\0';
6423
6424 if(jwin_file_browse_ex(title, fname, list, &sel, 2048, -1, -1, get_zc_font(font_lfont))==0)
6425 goto done;
6426
6427 if(exists(fname))
6428 {
6429 if(jwin_alert(title, fname, "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6430 goto done;
6431 }
6432
6433 // save midi i
6434
6435 if(save_midi(fname, (MIDI*)tunes[i].data) != 0)
6436 jwin_alert(title, "Error saving MIDI to", fname, NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6437
6438 done:
6439 chop_path(fname);
6440 ret = D_REDRAW;
6441 }
6442
6443 return ret;
6444 }
6445
6446 115 static ListData midi_list(midilist, &font);
6447
6448 static DIALOG midi_dlg[] =
6449 {
6450 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6451 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6452 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6453 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6454 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6455 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6456 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6457 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6458 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6459 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6460 };
6461
6462 void get_info(int32_t index)
6463 {
6464 int32_t i=0, m=0;
6465
6466 while(m<=index && i<=MAXMIDIS)
6467 {
6468 if(tunes[i].data)
6469 ++m;
6470
6471 ++i;
6472 }
6473
6474 --i;
6475
6476 if(i==MAXMIDIS && m<index)
6477 strcpy(text,"(null)");
6478 else
6479 {
6480 get_midi_info((MIDI*)tunes[i].data,zmi);
6481 get_midi_text((MIDI*)tunes[i].data,zmi,text);
6482 }
6483
6484 midi_dlg[0].dp2=get_zc_font(font_lfont);
6485 midi_dlg[3].dp = text;
6486 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6487 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6488
6489 if(dialog_running)
6490 {
6491 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6492 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6493 }
6494 }
6495
6496 int32_t onMIDICredits()
6497 {
6498 text = (char*)malloc(4096);
6499 zmi = (midi_info*)malloc(sizeof(midi_info));
6500
6501 if(!text || !zmi)
6502 {
6503 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6504 return D_O_K;
6505 }
6506
6507 bool do_pause_midi = midi_pos >= 0 && currmidi;
6508 auto restore_midi = currmidi;
6509 if(do_pause_midi)
6510 {
6511 paused_midi_pos = midi_pos;
6512 stop_midi();
6513 midi_suspended = midissuspHALTED;
6514 }
6515
6516 midi_dlg[0].dp2=get_zc_font(font_lfont);
6517 midi_dlg[2].d1 = 0;
6518 midi_dlg[2].d2 = 0;
6519 midi_dlg[4].flags = D_EXIT;
6520 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6521
6522 listening = false;
6523 dialog_running=false;
6524 get_info(0);
6525
6526 dialog_running=true;
6527
6528 large_dialog(midi_dlg);
6529
6530 do_zqdialog(midi_dlg,0);
6531 dialog_running=false;
6532
6533 if(listening)
6534 music_stop();
6535
6536 if(do_pause_midi)
6537 {
6538 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6539 midi_suspended = midissuspRESUME;
6540 currmidi = restore_midi;
6541 midi_pos = paused_midi_pos;
6542 }
6543
6544 if(text) free(text);
6545 if(zmi) free(zmi);
6546 return D_O_K;
6547 }
6548
6549 int32_t onAbout()
6550 {
6551 char buf1[80]={0};
6552 std::ostringstream oss;
6553 sprintf(buf1,"%s, Version: %s", ZC_PLAYER_NAME,ZC_PLAYER_V);
6554 oss << buf1 << '\n';
6555 sprintf(buf1, "%s", ALPHA_VER_STR);
6556 oss << buf1 << '\n';
6557 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6558 oss << buf1 << '\n';
6559 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6560 oss << buf1 << '\n';
6561 sprintf(buf1, "Tag: %s", getReleaseTag());
6562 oss << buf1 << '\n';
6563
6564 InfoDialog("About ZC", oss.str()).show();
6565 return D_O_K;
6566 }
6567
6568 int32_t onQuest()
6569 {
6570 char fname[100];
6571 strcpy(fname, get_filename(qstpath));
6572 quest_dlg[0].dp2=get_zc_font(font_lfont);
6573 quest_dlg[1].dp = fname;
6574
6575 if(QHeader.quest_number==0)
6576 sprintf(str_a,"Custom");
6577 else
6578 sprintf(str_a,"%d",QHeader.quest_number);
6579
6580 sprintf(str_s,"%s",VerStr(QHeader.zelda_version));
6581
6582 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6583 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6584
6585 large_dialog(quest_dlg);
6586
6587 do_zqdialog(quest_dlg, 0);
6588 return D_O_K;
6589 }
6590
6591 void call_vidmode_dlg();
6592 int32_t onVidMode()
6593 {
6594 call_vidmode_dlg();
6595 return D_O_K;
6596 }
6597
6598 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6599 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6600 //Added an extra statement, so that if the key is cleared to 0, the cleared
6601 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6602
6603 void load_ukeys(int32_t* arr)
6604 {
6605 arr[ukey_a] = Akey;
6606 arr[ukey_b] = Bkey;
6607 arr[ukey_s] = Skey;
6608 arr[ukey_l] = Lkey;
6609 arr[ukey_r] = Rkey;
6610 arr[ukey_p] = Pkey;
6611 arr[ukey_ex1] = Exkey1;
6612 arr[ukey_ex2] = Exkey2;
6613 arr[ukey_ex3] = Exkey3;
6614 arr[ukey_ex4] = Exkey4;
6615 arr[ukey_du] = DUkey;
6616 arr[ukey_dd] = DDkey;
6617 arr[ukey_dl] = DLkey;
6618 arr[ukey_dr] = DRkey;
6619 arr[ukey_mod1a] = cheat_modifier_keys[0];
6620 arr[ukey_mod1b] = cheat_modifier_keys[1];
6621 arr[ukey_mod2a] = cheat_modifier_keys[2];
6622 arr[ukey_mod2b] = cheat_modifier_keys[3];
6623 };
6624
6625 static const char* ukey_names[] = {
6626 "A", "B", "Start", "L", "R", "Map",
6627 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6628 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6629 "Cheat Mod R1", "Cheat Mod R2",
6630 };
6631 std::string get_ukey_name(int32_t k)
6632 {
6633 if (k < num_ukey) return ukey_names[k];
6634 return "";
6635 }
6636
6637 int32_t onKeyboard()
6638 {
6639 int32_t a = Akey;
6640 int32_t b = Bkey;
6641 int32_t s = Skey;
6642 int32_t l = Lkey;
6643 int32_t r = Rkey;
6644 int32_t p = Pkey;
6645 int32_t ex1 = Exkey1;
6646 int32_t ex2 = Exkey2;
6647 int32_t ex3 = Exkey3;
6648 int32_t ex4 = Exkey4;
6649 int32_t du = DUkey;
6650 int32_t dd = DDkey;
6651 int32_t dl = DLkey;
6652 int32_t dr = DRkey;
6653 int32_t mod1a = cheat_modifier_keys[0];
6654 int32_t mod1b = cheat_modifier_keys[1];
6655 int32_t mod2a = cheat_modifier_keys[2];
6656 int32_t mod2b = cheat_modifier_keys[3];
6657 bool done=false;
6658 int32_t ret;
6659
6660 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6661
6662 large_dialog(keyboard_control_dlg);
6663
6664 while(!done)
6665 {
6666 ret = do_zqdialog(keyboard_control_dlg,3);
6667
6668 if(ret==3) // OK
6669 {
6670 int32_t ukeys[num_ukey];
6671 load_ukeys(ukeys);
6672 std::vector<std::string> uniqueError;
6673 for(int32_t q = 0; q < num_ukey; ++q)
6674 {
6675 for(int32_t p = q+1; p < num_ukey; ++p)
6676 {
6677 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6678 {
6679 char buf[64];
6680 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6681 std::string str(buf);
6682 uniqueError.push_back(str);
6683 }
6684 }
6685 }
6686 if(uniqueError.size() == 0)
6687 {
6688 done = true;
6689 save_control_configs(true);
6690 }
6691 else
6692 {
6693 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6694 box_out("Cannot have duplicate keybinds!"); box_eol();
6695 for(std::vector<std::string>::iterator it = uniqueError.begin();
6696 it != uniqueError.end(); ++it)
6697 {
6698 box_out((*it).c_str()); box_eol();
6699 }
6700 box_end(true);
6701 }
6702 }
6703 else // Cancel
6704 {
6705 Akey = a;
6706 Bkey = b;
6707 Skey = s;
6708 Lkey = l;
6709 Rkey = r;
6710 Pkey = p;
6711 Exkey1 = ex1;
6712 Exkey2 = ex2;
6713 Exkey3 = ex3;
6714 Exkey4 = ex4;
6715 DUkey = du;
6716 DDkey = dd;
6717 DLkey = dl;
6718 DRkey = dr;
6719 cheat_modifier_keys[0] = mod1a;
6720 cheat_modifier_keys[1] = mod1b;
6721 cheat_modifier_keys[2] = mod2a;
6722 cheat_modifier_keys[3] = mod2b;
6723
6724 done=true;
6725 }
6726
6727 rest(1);
6728 }
6729
6730 return D_O_K;
6731 }
6732
6733 int32_t onGamepad()
6734 {
6735 if (al_get_num_joysticks() == 0)
6736 {
6737 InfoDialog("ZC", "No gamepads detected.").show();
6738 return D_O_K;
6739 }
6740
6741 int32_t a = Abtn;
6742 int32_t b = Bbtn;
6743 int32_t s = Sbtn;
6744 int32_t l = Lbtn;
6745 int32_t r = Rbtn;
6746 int32_t m = Mbtn;
6747 int32_t p = Pbtn;
6748 int32_t ex1 = Exbtn1;
6749 int32_t ex2 = Exbtn2;
6750 int32_t ex3 = Exbtn3;
6751 int32_t ex4 = Exbtn4;
6752 int32_t up = DUbtn;
6753 int32_t down = DDbtn;
6754 int32_t left = DLbtn;
6755 int32_t right = DRbtn;
6756 int32_t joy = joystick_index;
6757 int32_t stick_1 = js_stick_1_x_stick;
6758 int32_t stick_2 = js_stick_2_x_stick;
6759
6760 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6761 if(analog_movement)
6762 gamepad_dlg[56].flags|=D_SELECTED;
6763 else
6764 gamepad_dlg[56].flags&=~D_SELECTED;
6765
6766 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6767 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6768 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6769 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6770 // requires remapping every time.
6771 if (joystick_index >= al_get_num_joysticks())
6772 joystick_index = 0;
6773 gamepad_dlg[61].d2 = joystick_index;
6774
6775 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6776 if (!gamepad_dlg_cur_joystick)
6777 {
6778 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6779 return D_CLOSE;
6780 }
6781
6782 large_dialog(gamepad_dlg);
6783
6784 int32_t ret = do_zqdialog(gamepad_dlg,4);
6785
6786 if(ret == 4) //OK
6787 {
6788 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6789 joystick_index = gamepad_dlg[61].d2;
6790 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6791 if (!gamepad_dlg_cur_joystick)
6792 {
6793 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6794 return D_CLOSE;
6795 }
6796 js_stick_1_y_stick = js_stick_1_x_stick;
6797 js_stick_2_y_stick = js_stick_2_x_stick;
6798 save_control_configs(false);
6799 }
6800 else //Cancel
6801 {
6802 Abtn = a;
6803 Bbtn = b;
6804 Sbtn = s;
6805 Lbtn = l;
6806 Rbtn = r;
6807 Mbtn = m;
6808 Pbtn = p;
6809 Exbtn1 = ex1;
6810 Exbtn2 = ex2;
6811 Exbtn3 = ex3;
6812 Exbtn4 = ex4;
6813 DUbtn = up;
6814 DDbtn = down;
6815 DLbtn = left;
6816 DRbtn = right;
6817 joystick_index = joy;
6818 js_stick_1_x_stick = stick_1;
6819 js_stick_2_x_stick = stick_2;
6820 }
6821
6822 return D_O_K;
6823 }
6824
6825 int32_t onCheatKeys()
6826 {
6827 int32_t oldcheats[Cheat::Last][2];
6828 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6829
6830 bool done=false;
6831
6832 while(!done)
6833 {
6834 bool confirm = false;
6835 CheatKeysDialog(&confirm).show();
6836 if(confirm) // OK
6837 {
6838 std::vector<std::string> uniqueError;
6839 char buf[512];
6840 for(size_t q = 1; q < Cheat::Last; ++q)
6841 {
6842 if(cheatkeys[q][1] && !cheatkeys[q][0])
6843 {
6844 cheatkeys[q][0] = cheatkeys[q][1];
6845 cheatkeys[q][1] = 0;
6846 }
6847 }
6848 for(size_t q = 1; q < Cheat::Last; ++q)
6849 {
6850 if(!bindable_cheat((Cheat)q)) continue;
6851 for(size_t p = q+1; p < Cheat::Last; ++p)
6852 {
6853 if(!bindable_cheat((Cheat)p)) continue;
6854 for(size_t q2 = 0; q2 <= 1; ++q2)
6855 for(size_t p2 = 0; p2 <= 1; ++p2)
6856 {
6857 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6858 {
6859 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6860 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6861 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6862 get_keystr(cheatkeys[q][q2])));
6863 }
6864 }
6865 }
6866 }
6867 if(uniqueError.size() == 0)
6868 {
6869 done = true;
6870 save_cheatkeys();
6871 }
6872 else
6873 {
6874 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6875 box_out("Cannot have duplicate keybinds!"); box_eol();
6876 for(std::vector<std::string>::iterator it = uniqueError.begin();
6877 it != uniqueError.end(); ++it)
6878 {
6879 box_out((*it).c_str()); box_eol();
6880 }
6881 box_end(true);
6882 }
6883 }
6884 else // Cancel
6885 {
6886 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6887 done=true;
6888 }
6889 rest(1);
6890 }
6891
6892 return D_O_K;
6893 }
6894
6895 int32_t onSound()
6896 {
6897 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6898 {
6899 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6900 {
6901 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6902 }
6903 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6904 {
6905 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6906 }
6907 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6908 {
6909 emusic_volume = (int32_t)FFCore.usr_music_volume;
6910 }
6911 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6912 {
6913 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6914 }
6915 }
6916 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6917 {
6918 pan_style = (int32_t)FFCore.usr_panstyle;
6919 }
6920
6921 int32_t m = midi_volume;
6922 int32_t d = digi_volume;
6923 int32_t e = emusic_volume;
6924 int32_t b = zcmusic_bufsz;
6925 int32_t s = sfx_volume;
6926 int32_t p = pan_style;
6927 pan_style = vbound(pan_style,0,3);
6928
6929 sound_dlg[0].dp2=get_zc_font(font_lfont);
6930
6931 large_dialog(sound_dlg);
6932
6933 midi_dp[1] = sound_dlg[6].x;
6934 midi_dp[2] = sound_dlg[6].y;
6935 digi_dp[1] = sound_dlg[7].x;
6936 digi_dp[2] = sound_dlg[7].y;
6937 emus_dp[1] = sound_dlg[8].x;
6938 emus_dp[2] = sound_dlg[8].y;
6939 buf_dp[1] = sound_dlg[9].x;
6940 buf_dp[2] = sound_dlg[9].y;
6941 sfx_dp[1] = sound_dlg[10].x;
6942 sfx_dp[2] = sound_dlg[10].y;
6943 pan_dp[1] = sound_dlg[11].x;
6944 pan_dp[2] = sound_dlg[11].y;
6945 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6946 sound_dlg[16].d2 = (digi_volume==255) ? 32 : digi_volume>>3;
6947 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6948 sound_dlg[18].d2 = zcmusic_bufsz;
6949 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6950 sound_dlg[20].d2 = pan_style;
6951
6952 int32_t ret = do_zqdialog(sound_dlg,1);
6953
6954 if(ret==2)
6955 {
6956 master_volume(digi_volume,midi_volume);
6957 if (zcmusic)
6958 zcmusic_set_volume(zcmusic, emusic_volume);
6959
6960 int32_t temp_volume = sfx_volume;
6961 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6962 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6963 for(int32_t i=0; i<WAV_COUNT; ++i)
6964 {
6965 //allegro assertion fails when passing in -1 as voice -DD
6966 if(sfx_voice[i] > 0)
6967 voice_set_volume(sfx_voice[i], temp_volume);
6968 }
6969 zc_set_config(sfx_sect,"digi",digi_volume);
6970 zc_set_config(sfx_sect,"midi",midi_volume);
6971 zc_set_config(sfx_sect,"sfx",sfx_volume);
6972 zc_set_config(sfx_sect,"emusic",emusic_volume);
6973 zc_set_config(sfx_sect,"pan",pan_style);
6974 zc_set_config(sfx_sect,"zcmusic_bufsz",zcmusic_bufsz);
6975 }
6976 else
6977 {
6978 midi_volume = m;
6979 digi_volume = d;
6980 emusic_volume = e;
6981 zcmusic_bufsz = b;
6982 sfx_volume = s;
6983 pan_style = p;
6984 }
6985
6986 return D_O_K;
6987 }
6988
6989 int32_t queding(char const* s1, char const* s2, char const* s3)
6990 {
6991 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6992 }
6993
6994 int32_t onQuit()
6995 {
6996 if(Playing)
6997 {
6998 int32_t ret=0;
6999
7000 if(get_qr(qr_NOCONTINUE))
7001 {
7002 if(standalone_mode)
7003 {
7004 ret=queding("End current game?",
7005 "The continue screen is disabled; the game",
7006 "will be reloaded from the last save.");
7007 }
7008 else
7009 {
7010 ret=queding("End current game?",
7011 "The continue screen is disabled. You will",
7012 "be returned to the file select screen.");
7013 }
7014 }
7015 else
7016 ret=queding("End current game?",NULL,NULL);
7017
7018 if(ret==1)
7019 {
7020 disableClickToFreeze=false;
7021 Quit=qQUIT;
7022
7023 // Trying to evade a door repair charge?
7024 if(repaircharge)
7025 {
7026 game->change_drupy(-repaircharge);
7027 repaircharge=0;
7028 }
7029
7030 return D_CLOSE;
7031 }
7032 }
7033
7034 return D_O_K;
7035 }
7036
7037 int32_t onTryQuitMenu()
7038 {
7039 return onTryQuit(true);
7040 }
7041
7042 int32_t onTryQuit(bool inMenu)
7043 {
7044 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
7045 {
7046 if(active_cutscene.can_f6())
7047 {
7048 if(get_qr(qr_OLD_F6))
7049 {
7050 if(inMenu) onQuit();
7051 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
7052 }
7053 else
7054 {
7055 disableClickToFreeze=false;
7056 GameFlags |= GAMEFLAG_TRYQUIT;
7057 }
7058 return D_CLOSE;
7059 }
7060 else active_cutscene.error();
7061 }
7062
7063 return D_O_K;
7064 }
7065
7066 int32_t onReset()
7067 {
7068 if(queding(" Reset system? ",NULL,NULL)==1)
7069 {
7070 disableClickToFreeze=false;
7071 Quit=qRESET;
7072 replay_quit();
7073 return D_CLOSE;
7074 }
7075
7076 return D_O_K;
7077 }
7078
7079 int32_t onExit()
7080 {
7081 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
7082 {
7083 Quit=qEXIT;
7084 return D_CLOSE;
7085 }
7086
7087 return D_O_K;
7088 }
7089
7090 int32_t onDebug()
7091 {
7092 if(debug_enabled)
7093 set_debug(!get_debug());
7094 return D_O_K;
7095 }
7096
7097 int32_t onHeartBeep()
7098 {
7099 heart_beep=!heart_beep;
7100 zc_set_config(cfg_sect,"heart_beep",heart_beep);
7101 return D_O_K;
7102 }
7103
7104 int32_t onSaveIndicator()
7105 {
7106 use_save_indicator = use_save_indicator ? 0 : 1;
7107 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
7108 return D_O_K;
7109 }
7110
7111 int32_t onEpilepsy()
7112 {
7113 if(jwin_alert3(
7114 "Epilepsy Flash Reduction",
7115 "Enabling this will reduce the intensity of flashing and screen wave effects.",
7116 "Disabling this will restore standard flash and wavy behaviour.",
7117 "Proceed?",
7118 "&Yes",
7119 "&No",
7120 NULL,
7121 'y',
7122 'n',
7123 0,
7124 get_zc_font(font_lfont)) == 1)
7125 {
7126 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
7127 zc_set_config("zeldadx","checked_epilepsy",1);
7128 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
7129 }
7130 return D_O_K;
7131 }
7132
7133 bool rc = false;
7134
7135 static DIALOG getnum_dlg[] =
7136 {
7137 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
7138 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
7139 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
7140 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
7141 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7142 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7143 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7144 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7145 };
7146
7147 int32_t getnumber(const char *prompt,int32_t initialval)
7148 {
7149 char buf[20];
7150 sprintf(buf,"%d",initialval);
7151 getnum_dlg[0].dp=(void *)prompt;
7152 getnum_dlg[0].dp2=get_zc_font(font_lfont);
7153 getnum_dlg[2].dp=buf;
7154
7155 large_dialog(getnum_dlg);
7156
7157 if(do_zqdialog(getnum_dlg,2)==3)
7158 return atoi(buf);
7159
7160 return initialval;
7161 }
7162
7163 int32_t onLife()
7164 {
7165 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
7166 cheats_enqueue(Cheat::Life, value);
7167 return D_O_K;
7168 }
7169
7170 int32_t onHeartC()
7171 {
7172 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
7173 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
7174 cheats_enqueue(Cheat::MaxLife, max_life);
7175 cheats_enqueue(Cheat::Life, life);
7176 return D_O_K;
7177 }
7178
7179 int32_t onMagicC()
7180 {
7181 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
7182 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
7183 cheats_enqueue(Cheat::MaxMagic, max_magic);
7184 cheats_enqueue(Cheat::Magic, magic);
7185 return D_O_K;
7186 }
7187
7188 int32_t onRupies()
7189 {
7190 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
7191 cheats_enqueue(Cheat::Rupies, value);
7192 return D_O_K;
7193 }
7194
7195 int32_t onMaxBombs()
7196 {
7197 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
7198 cheats_enqueue(Cheat::MaxBombs, value);
7199 cheats_enqueue(Cheat::Bombs, value);
7200 return D_O_K;
7201 }
7202
7203 int32_t onRefillLife()
7204 {
7205 cheats_enqueue(Cheat::Life, game->get_maxlife());
7206 return D_O_K;
7207 }
7208 int32_t onRefillMagic()
7209 {
7210 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7211 return D_O_K;
7212 }
7213 int32_t onClock()
7214 {
7215 cheats_enqueue(Cheat::Clock);
7216 return D_O_K;
7217 }
7218
7219 int32_t onQstPath()
7220 {
7221 char path[2048];
7222
7223 chop_path(qstdir);
7224 strcpy(path,qstdir);
7225
7226 go();
7227
7228 if(jwin_dfile_select_ex("Quest File Directory", path, "qst", 2048, -1, -1, get_zc_font(font_lfont)))
7229 {
7230 chop_path(path);
7231 fix_filename_case(path);
7232 fix_filename_slashes(path);
7233 strcpy(qstdir,path);
7234 strcpy(qstpath,qstdir);
7235 zc_set_config("zeldadx","quest_dir",qstdir);
7236 flush_config_file();
7237 }
7238
7239 comeback();
7240 return D_O_K;
7241 }
7242
7243 #include "dialog/cheat_dialog.h"
7244 int32_t onCheat()
7245 {
7246 call_setcheat_dialog();
7247 game->set_cheat(maxcheat);
7248 if(cheat) game->did_cheat(true);
7249 return D_O_K;
7250 }
7251
7252 int32_t onCheatRupies()
7253 {
7254 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7255 return D_O_K;
7256 }
7257
7258 int32_t onCheatArrows()
7259 {
7260 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7261 return D_O_K;
7262 }
7263
7264 int32_t onCheatBombs()
7265 {
7266 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7267 return D_O_K;
7268 }
7269
7270 // *** screen saver
7271
7272 9286090 int32_t after_time()
7273 {
7274
1/2
✓ Branch 0 taken 9286090 times.
✗ Branch 1 not taken.
9286090 if(ss_enable == 0)
7275 return INT_MAX;
7276
7277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
9286090 if(ss_after <= 0)
7278 return 5 * 60;
7279
7280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
9286090 if(ss_after <= 3)
7281 return ss_after * 15 * 60;
7282
7283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286090 times.
9286090 if(ss_after <= 13)
7284 return (ss_after - 3) * 60 * 60;
7285
7286 9286090 return MAX_IDLE + 1;
7287 9286090 }
7288
7289 static const char *after_str[15] =
7290 {
7291 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7292 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7293 "Never"
7294 };
7295
7296 const char *after_list(int32_t index, int32_t *list_size)
7297 {
7298 if(index < 0)
7299 {
7300 *list_size = 15;
7301 return NULL;
7302 }
7303
7304 return after_str[index];
7305 }
7306
7307 115 static ListData after__list(after_list, &font);
7308
7309 static DIALOG scrsaver_dlg[] =
7310 {
7311 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7312 115 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7313 115 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7314 115 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7315 115 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7316 115 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7317 115 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7318 115 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7319 115 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7320 115 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7321 115 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7322 115 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7323 115 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7324 115 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7325 };
7326
7327 int32_t onScreenSaver()
7328 {
7329 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7330 int32_t oldcfgs[3];
7331 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7332 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7333 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7334
7335 large_dialog(scrsaver_dlg);
7336
7337 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7338
7339 if(ret == 8 || ret == 9)
7340 {
7341 ss_after = scrsaver_dlg[5].d1;
7342 ss_speed = scrsaver_dlg[6].d2;
7343 ss_density = scrsaver_dlg[7].d2;
7344 if(oldcfgs[0] != ss_after)
7345 zc_set_config(cfg_sect,"ss_after",ss_after);
7346 if(oldcfgs[1] != ss_speed)
7347 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7348 if(oldcfgs[2] != ss_density)
7349 zc_set_config(cfg_sect,"ss_density",ss_density);
7350 }
7351
7352 if(ret == 9)
7353 // preview Screen Saver
7354 {
7355 clear_keybuf();
7356 Matrix(ss_speed, ss_density, 30);
7357 system_pal(true);
7358 sys_mouse();
7359 }
7360
7361 return D_O_K;
7362 }
7363
7364 /***** Menus *****/
7365
7366 static MENU game_menu[] =
7367 {
7368 { (char *)"&Continue\tESC", onContinue, NULL, 0, NULL },
7369 { (char *)"", NULL, NULL, 0, NULL },
7370 { (char *)"L&oad Quest...", onCustomGame, NULL, 0, NULL },
7371 { (char *)"&End Game\tF6", onTryQuitMenu, NULL, 0, NULL },
7372 { (char *)"", NULL, NULL, 0, NULL },
7373 #ifdef __EMSCRIPTEN__
7374 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7375 #elif defined(ALLEGRO_MACOSX)
7376 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7377 { (char *)"&Quit\tF8", onExit, NULL, 0, NULL },
7378 #else
7379 { (char *)"&Reset\tF9", onReset, NULL, 0, NULL },
7380 { (char *)"&Quit\tF10", onExit, NULL, 0, NULL },
7381 #endif
7382 { NULL, NULL, NULL, 0, NULL }
7383 };
7384
7385 static MENU snapshot_format_menu[] =
7386 {
7387 { (char *)"&BMP", onSetSnapshotFormat, NULL, 0, NULL },
7388 { (char *)"&GIF", onSetSnapshotFormat, NULL, 0, NULL },
7389 { (char *)"&JPG", onSetSnapshotFormat, NULL, 0, NULL },
7390 { (char *)"&PNG", onSetSnapshotFormat, NULL, 0, NULL },
7391 { (char *)"PC&X", onSetSnapshotFormat, NULL, 0, NULL },
7392 { (char *)"&TGA", onSetSnapshotFormat, NULL, 0, NULL },
7393 { NULL, NULL, NULL, 0, NULL }
7394 };
7395
7396 static MENU controls_menu[] =
7397 {
7398 { (char *)"Key&board...", onKeyboard, NULL, 0, NULL },
7399 { (char *)"&Gamepad...", onGamepad, NULL, 0, NULL },
7400 { (char *)"&Cheat Keys...", onCheatKeys, NULL, 0, NULL },
7401 { NULL, NULL, NULL, 0, NULL }
7402 };
7403
7404 static MENU name_entry_mode_menu[] =
7405 {
7406 { (char *)"&Keyboard", onKeyboardEntry, NULL, 0, NULL },
7407 { (char *)"&Letter Grid", onLetterGridEntry, NULL, 0, NULL },
7408 { (char *)"&Extended Letter Grid", onExtLetterGridEntry, NULL, 0, NULL },
7409 { NULL, NULL, NULL, 0, NULL }
7410 };
7411
7412 static void set_controls_menu_active()
7413 {
7414
7415 }
7416
7417 static MENU window_menu[] =
7418 {
7419 { "Lock Aspect Ratio", onDragAspect, NULL, 0, NULL },
7420 { "Lock Integer Scale", onIntegerScaling, NULL, 0, NULL },
7421 { "Save Size Changes", onSaveDragResize, NULL, 0, NULL },
7422 { "Save Position Changes", onWinPosSave, NULL, 0, NULL },
7423 { "Stretch Game Area", onStretchGame, NULL, 0, NULL },
7424 { NULL, NULL, NULL, 0, NULL }
7425 };
7426 static MENU options_menu[] =
7427 {
7428 { "Name &Entry Mode", NULL, name_entry_mode_menu, 0, NULL },
7429 { "S&napshot Format", NULL, snapshot_format_menu, 0, NULL },
7430 { "&Window Settings", NULL, window_menu, 0, NULL },
7431 { "Epilepsy Flash Reduction", onEpilepsy, NULL, 0, NULL },
7432 { "Pause In Background", onPauseInBackground, NULL, 0, NULL },
7433 { NULL, NULL, NULL, 0, NULL }
7434 };
7435 static MENU settings_menu[] =
7436 {
7437 { "&Sound...", onSound, NULL, 0, NULL },
7438 { "C&ontrols", NULL, controls_menu, 0, NULL },
7439 { "", NULL, NULL, 0, NULL },
7440 { "Options", NULL, options_menu, 0, NULL },
7441 { "", NULL, NULL, 0, NULL },
7442 //
7443 { "&Cap FPS\tF1", onVsync, NULL, 0, NULL },
7444 { "Show &FPS\tF2", onShowFPS, NULL, 0, NULL },
7445 { "Click to Freeze", onClickToFreeze, NULL, 0, NULL },
7446 { "Cont. &Heart Beep", onHeartBeep, NULL, 0, NULL },
7447 { "Show Trans. &Layers", onTransLayers, NULL, 0, NULL },
7448 //
7449 { "Up+A+B To &Quit", onNESquit, NULL, 0, NULL },
7450 { "Volume &Keys", onVolKeys, NULL, 0, NULL },
7451 { "Sa&ve Indicator", onSaveIndicator, NULL, 0, NULL },
7452 { "", NULL, NULL, 0, NULL },
7453 { "Debu&g", onDebug, NULL, 0, NULL },
7454 //
7455 { NULL, NULL, NULL, 0, NULL }
7456 };
7457
7458
7459 static MENU misc_menu[] =
7460 {
7461 { (char *)"&About...", onAbout, NULL, 0, NULL },
7462 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7463 { (char *)"&Credits...", onCredits, NULL, D_DISABLED, NULL },
7464 { (char *)"&Fullscreen", onFullscreenMenu, NULL, 0, NULL },
7465 { (char *)"&Video Mode...", onVidMode, NULL, 0, NULL },
7466 { (char *)"", NULL, NULL, 0, NULL },
7467 //5
7468 { (char *)"&Quest Info...", onQuest, NULL, 0, NULL },
7469 { (char *)"Quest &MIDI Info...", onMIDICredits, NULL, 0, NULL },
7470 { (char *)"Quest &Directory...", onQstPath, NULL, 0, NULL },
7471 { (char *)"", NULL, NULL, 0, NULL },
7472 { (char *)"Take &Snapshot\tF12", onSnapshot, NULL, 0, NULL },
7473 //10
7474 { (char *)"Sc&reen Saver...", onScreenSaver, NULL, 0, NULL },
7475 { (char *)"Save ZC Configuration", OnSaveZCConfig, NULL, 0, NULL },
7476 { (char *)"Show ZASM Debugger", onConsoleZASM, NULL, 0, NULL },
7477 { (char *)"Show ZScript Debugger", onConsoleZScript, NULL, 0, NULL },
7478 { (char *)"Clear Console on Qst Load", onClrConsoleOnLoad, NULL, 0, NULL },
7479 //15
7480 { (char *)"Clear Directory Cache", OnnClearQuestDir, NULL, 0, NULL },
7481 { NULL, NULL, NULL, 0, NULL }
7482 };
7483
7484 static MENU refill_menu[] =
7485 {
7486 { (char *)"&Life", onRefillLife, NULL, 0, NULL },
7487 { (char *)"&Magic", onRefillMagic, NULL, 0, NULL },
7488 { (char *)"&Bombs", onCheatBombs, NULL, 0, NULL },
7489 { (char *)"&Rupees", onCheatRupies, NULL, 0, NULL },
7490 { (char *)"&Arrows", onCheatArrows, NULL, 0, NULL },
7491 { NULL, NULL, NULL, 0, NULL }
7492 };
7493
7494 static MENU show_menu[] =
7495 {
7496 { (char *)"Combos", onShowLayer0, NULL, 0, NULL },
7497 { (char *)"Layer 1", onShowLayer1, NULL, 0, NULL },
7498 { (char *)"Layer 2", onShowLayer2, NULL, 0, NULL },
7499 { (char *)"Layer 3", onShowLayer3, NULL, 0, NULL },
7500 { (char *)"Layer 4", onShowLayer4, NULL, 0, NULL },
7501 { (char *)"Layer 5", onShowLayer5, NULL, 0, NULL },
7502 { (char *)"Layer 6", onShowLayer6, NULL, 0, NULL },
7503 { (char *)"Overhead Combos", onShowLayerO, NULL, 0, NULL },
7504 { (char *)"Push Blocks", onShowLayerP, NULL, 0, NULL },
7505 { (char *)"Freeform Combos", onShowLayerF, NULL, 0, NULL },
7506 { (char *)"Sprites", onShowLayerS, NULL, 0, NULL },
7507 { (char *)"", NULL, NULL, 0, NULL },
7508 { (char *)"Current FFC Scripts", onShowFFScripts, NULL, 0, NULL },
7509 { (char *)"", NULL, NULL, 0, NULL },
7510 { (char *)"Walkability", onShowLayerW, NULL, 0, NULL },
7511 { (char *)"Hitboxes", onShowHitboxes, NULL, 0, NULL },
7512 { (char *)"Effects", onShowLayerE, NULL, 0, NULL },
7513 { (char *)"Info Opacity", onShowInfoOpacity, NULL, 0, NULL },
7514 { NULL, NULL, NULL, 0, NULL }
7515 };
7516
7517 static MENU cheat_menu[] =
7518 {
7519 { (char *)"Set &Cheat", onCheat, NULL, 0, NULL },
7520 { (char *)"", NULL, NULL, 0, NULL },
7521 { (char *)"Re&fill", NULL, refill_menu, 0, NULL },
7522 { (char *)"", NULL, NULL, 0, NULL },
7523 { (char *)"&Invincible", onClock, NULL, 0, NULL },
7524 { (char *)"Ma&x Bombs...", onMaxBombs, NULL, 0, NULL },
7525 { (char *)"&Heart Containers...", onHeartC, NULL, 0, NULL },
7526 { (char *)"&Magic Containers...", onMagicC, NULL, 0, NULL },
7527 { (char *)"", NULL, NULL, 0, NULL },
7528 { (char *)"&Player Data...", onCheatConsole, NULL, 0, NULL },
7529 { (char *)"", NULL, NULL, 0, NULL },
7530 { (char *)"Walk Through &Walls", onNoWalls, NULL, 0, NULL },
7531 { (char *)"Player Ignores Side&view", onIgnoreSideview, NULL, 0, NULL },
7532 { (char *)"&Quick Movement", onGoFast, NULL, 0, NULL },
7533 { (char *)"&Kill All Enemies", onKillCheat, NULL, 0, NULL },
7534 { (char *)"Trigger &Secrets", onSecretsCheat, NULL, 0, NULL },
7535 { (char *)"Trigger Secrets Perm", onSecretsCheatPerm, NULL, 0, NULL },
7536 { (char *)"Show/Hide Layer", NULL, show_menu, 0, NULL },
7537 { (char *)"Toggle &Light", onLightSwitch, NULL, 0, NULL },
7538 { (char *)"&Goto Location...", onGoTo, NULL, 0, NULL },
7539 { NULL, NULL, NULL, 0, NULL }
7540 };
7541
7542 #if DEVLEVEL > 0
7543 int32_t devLogging();
7544 int32_t devDebug();
7545 int32_t devTimestmp();
7546 #if DEVLEVEL > 1
7547 int32_t setCheat();
7548 #endif //DEVLEVEL > 1
7549 enum
7550 {
7551 dv_log,
7552 // dv_dbg,
7553 dv_tmpstmp,
7554 #if DEVLEVEL > 1
7555 dv_nil,
7556 dv_setcheat,
7557 #endif //DEVLEVEL > 1
7558 dv_max
7559 };
7560 static MENU dev_menu[] =
7561 {
7562 { (char *)"&Force Error Log", devLogging, NULL, 0, NULL },
7563 // { (char *)"&Extra Debug Log", devDebug, NULL, 0, NULL },
7564 { (char *)"&Timestamp Log", devTimestmp, NULL, 0, NULL },
7565 #if DEVLEVEL > 1
7566 { (char *)"", NULL, NULL, 0, NULL },
7567 { (char *)"Set &Cheat", setCheat, NULL, 0, NULL },
7568 #endif //DEVLEVEL > 1
7569 { NULL, NULL, NULL, 0, NULL }
7570 };
7571 int32_t devLogging()
7572 {
7573 dev_logging = !dev_logging;
7574 dev_menu[dv_log].flags = dev_logging ? D_SELECTED : 0;
7575 return D_O_K;
7576 }
7577 // int32_t devDebug()
7578 // {
7579 // dev_debug = !dev_debug;
7580 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7581 // return D_O_K;
7582 // }
7583 int32_t devTimestmp()
7584 {
7585 dev_timestmp = !dev_timestmp;
7586 dev_menu[dv_tmpstmp].flags = dev_timestmp ? D_SELECTED : 0;
7587 return D_O_K;
7588 }
7589 #if DEVLEVEL > 1
7590 int32_t setCheat()
7591 {
7592 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7593 return D_O_K;
7594 }
7595 #endif //DEVLEVEL > 1
7596 #endif //DEVLEVEL > 0
7597
7598 MENU the_player_menu[] =
7599 {
7600 { (char *)"&Game", NULL, game_menu, 0, NULL },
7601 { (char *)"&Settings", NULL, settings_menu, 0, NULL },
7602 { (char *)"&Cheat", NULL, cheat_menu, 0, NULL },
7603 { (char *)"Replay", NULL, replay_menu, 0, NULL },
7604 { (char *)"&ZC", NULL, misc_menu, 0, NULL },
7605 #if DEVLEVEL > 0
7606 { (char *)"&Dev", NULL, dev_menu, 0, NULL },
7607 #endif
7608 { NULL, NULL, NULL, 0, NULL }
7609 };
7610 int32_t onPauseInBackground()
7611 {
7612 if(jwin_alert3(
7613 "Toggle Pause In Background",
7614 "This action will change whether ZC Player pauses when the window loses focus.",
7615 "",
7616 "Proceed?",
7617 "&Yes",
7618 "&No",
7619 NULL,
7620 'y',
7621 'n',
7622 0,
7623 get_zc_font(font_lfont)) == 1)
7624 {
7625 pause_in_background = pause_in_background ? 0 : 1;
7626 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7627 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7628 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7629 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7630 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7631 }
7632 options_menu[4].flags =(pause_in_background)?D_SELECTED:0;
7633 return D_O_K;
7634 }
7635
7636 int32_t onKeyboardEntry()
7637 {
7638 NameEntryMode=0;
7639 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7640 return D_O_K;
7641 }
7642
7643 int32_t onLetterGridEntry()
7644 {
7645 NameEntryMode=1;
7646 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7647 return D_O_K;
7648 }
7649
7650 int32_t onExtLetterGridEntry()
7651 {
7652 NameEntryMode=2;
7653 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7654 return D_O_K;
7655 }
7656
7657 static BITMAP* oldscreen;
7658 int32_t onFullscreenMenu()
7659 {
7660 // super hacks
7661 screen = oldscreen;
7662 if (onFullscreen() == D_REDRAW)
7663 {
7664 oldscreen = screen;
7665 }
7666 screen = menu_bmp;
7667 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7668 return D_O_K;
7669 }
7670
7671 115 void fix_menu()
7672 {
7673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if(!debug_enabled)
7674 115 settings_menu[13].text = NULL;
7675 115 }
7676
7677 static DIALOG system_dlg[] =
7678 {
7679 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
7680 { jwin_menu_proc, 0, 0, 0, 0, 0, 0, 0, D_USER, 0, 0, (void *) the_player_menu, NULL, NULL },
7681 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onVsync, NULL, NULL },
7682 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F2, 0, (void *) onShowFPS, NULL, NULL },
7683 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F6, 0, (void *) onTryQuitMenu, NULL, NULL },
7684 #ifndef ALLEGRO_MACOSX
7685 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F9, 0, (void *) onReset, NULL, NULL },
7686 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F10, 0, (void *) onExit, NULL, NULL },
7687 #else
7688 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F7, 0, (void *) onReset, NULL, NULL },
7689 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F8, 0, (void *) onExit, NULL, NULL },
7690 #endif
7691 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F12, 0, (void *) onSnapshot, NULL, NULL },
7692 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_TAB, 0, (void *) onDebug, NULL, NULL },
7693 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7694 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7695 };
7696
7697 void reset_snapshot_format_menu()
7698 {
7699 for(int32_t i=0; i<ssfmtMAX; ++i)
7700 {
7701 snapshot_format_menu[i].flags=0;
7702 }
7703 }
7704
7705 int32_t onSetSnapshotFormat()
7706 {
7707 switch(active_menu->text[1])
7708 {
7709 case 'B': //"&BMP"
7710 SnapshotFormat=0;
7711 break;
7712
7713 case 'G': //"&GIF"
7714 SnapshotFormat=1;
7715 break;
7716
7717 case 'J': //"&JPG"
7718 SnapshotFormat=2;
7719 break;
7720
7721 case 'P': //"&PNG"
7722 SnapshotFormat=3;
7723 break;
7724
7725 case 'C': //"PC&X"
7726 SnapshotFormat=4;
7727 break;
7728
7729 case 'T': //"&TGA"
7730 SnapshotFormat=5;
7731 break;
7732
7733 case 'L': //"&LBM"
7734 SnapshotFormat=6;
7735 break;
7736 }
7737 zc_set_config("zeldadx", "snapshot_format", SnapshotFormat);
7738
7739 snapshot_format_menu[SnapshotFormat].flags=D_SELECTED;
7740 return D_O_K;
7741 }
7742
7743
7744 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7745 {
7746 PALETTE tmp;
7747
7748 for(int32_t i=0; i<256; i++)
7749 {
7750 tmp[i].r=r;
7751 tmp[i].g=g;
7752 tmp[i].b=b;
7753 }
7754
7755 fade_interpolate(src,tmp,dest,pos,from,to);
7756 }
7757
7758 14 void system_pal(bool force)
7759 {
7760
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(is_sys_pal && !force) return;
7761 14 is_sys_pal = true;
7762 14 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7763 14 hw_palette = &syspal;
7764 14 update_hw_pal = true;
7765 14 }
7766
7767 static uint32_t entered_sys_pal = 0;
7768 14 void enter_sys_pal()
7769 {
7770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(is_sys_pal)
7771 {
7772 if(entered_sys_pal)
7773 ++entered_sys_pal;
7774 return;
7775 }
7776 14 sys_mouse();
7777 14 system_pal(true);
7778 14 ++entered_sys_pal;
7779 14 }
7780 14 void exit_sys_pal()
7781 {
7782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(entered_sys_pal)
7783 {
7784
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!--entered_sys_pal)
7785 {
7786 14 game_pal();
7787 14 game_mouse();
7788 14 }
7789 14 }
7790 14 }
7791
7792 void switch_out_callback()
7793 {
7794 if (pause_in_background && !MenuOpen)
7795 {
7796 System();
7797 }
7798 }
7799
7800 void switch_in_callback()
7801 {
7802 }
7803
7804 422 void game_pal()
7805 {
7806 422 is_sys_pal = false;
7807 422 entered_sys_pal = 0;
7808 422 hw_palette = &RAMpal;
7809 422 update_hw_pal = true;
7810 422 }
7811
7812 static char bar_str[] = "";
7813
7814 14 void music_pause()
7815 {
7816 //al_pause_duh(tmplayer);
7817 14 zcmusic_pause(zcmusic, ZCM_PAUSE);
7818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(zcmixer->oldtrack)
7819 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7820 14 zc_midi_pause();
7821 14 }
7822
7823 void music_resume()
7824 {
7825 //al_resume_duh(tmplayer);
7826 zcmusic_pause(zcmusic, ZCM_RESUME);
7827 if (zcmixer->oldtrack)
7828 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7829 zc_midi_resume();
7830 }
7831
7832 3359 void music_stop()
7833 {
7834 //al_stop_duh(tmplayer);
7835 //unload_duh(tmusic);
7836 //tmusic=NULL;
7837 //tmplayer=NULL;
7838 3359 zcmusic_stop(zcmusic);
7839 3359 zcmusic_unload_file(zcmusic);
7840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3359 times.
3359 if (zcmixer->oldtrack)
7841 {
7842 zcmusic_stop(zcmixer->oldtrack);
7843 zcmusic_unload_file(zcmixer->oldtrack);
7844 }
7845 3359 zcmixer->newtrack = NULL;
7846 3359 zc_stop_midi();
7847 3359 currmidi=-1;
7848 3359 }
7849
7850 void System()
7851 {
7852 mouse_down=gui_mouse_b();
7853 music_pause();
7854 pause_all_sfx();
7855 MenuOpen = true;
7856 enter_sys_pal();
7857 // FONT *oldfont=font;
7858 // font=tfont;
7859
7860 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7861 misc_menu[3].flags =(isFullScreen()==1)?D_DISABLED:0;
7862
7863 game_menu[2].flags = getsaveslot() > -1 ? 0 : D_DISABLED;
7864 #if DEVLEVEL > 1
7865 dev_menu[dv_setcheat].flags = Playing ? 0 : D_DISABLED;
7866 #endif
7867 game_menu[3].flags =
7868 misc_menu[5].flags = Playing ? 0 : D_DISABLED;
7869 misc_menu[7].flags = !Playing ? 0 : D_DISABLED;
7870 clear_keybuf();
7871
7872 DIALOG_PLAYER *p;
7873
7874 clear_bitmap(menu_bmp);
7875 oldscreen = screen;
7876 screen = menu_bmp;
7877
7878 p = init_dialog(system_dlg,-1);
7879
7880 // drop the menu on startup if menu button pressed
7881 if(joybtn(Mbtn)||zc_getrawkey(KEY_ESC))
7882 simulate_keypress(KEY_G << 8);
7883
7884 do
7885 {
7886 if(handle_close_btn_quit())
7887 break;
7888
7889 rest(17);
7890
7891 if(mouse_down && !gui_mouse_b())
7892 mouse_down=0;
7893
7894 settings_menu[1].flags = replay_is_replaying() ? D_DISABLED : 0;
7895 settings_menu[5].flags = Throttlefps?D_SELECTED:0;
7896 settings_menu[6].flags = ShowFPS?D_SELECTED:0;
7897 settings_menu[7].flags = ClickToFreeze?D_SELECTED:0;
7898 settings_menu[9].flags = TransLayers?D_SELECTED:0;
7899 settings_menu[10].flags = NESquit?D_SELECTED:0;
7900 settings_menu[11].flags = volkeys?D_SELECTED:0;
7901
7902 window_menu[0].flags = DragAspect?D_SELECTED:0;
7903 window_menu[1].flags = scaleForceInteger?D_SELECTED:0;
7904 window_menu[2].flags = SaveDragResize?D_SELECTED:0;
7905 window_menu[3].flags = SaveWinPos?D_SELECTED:0;
7906 window_menu[4].flags = stretchGame?D_SELECTED:0;
7907
7908 options_menu[3].flags = (epilepsyFlashReduction) ? D_SELECTED : 0;
7909 options_menu[4].flags = (pause_in_background)?D_SELECTED:0;
7910
7911 name_entry_mode_menu[0].flags = (NameEntryMode==0)?D_SELECTED:0;
7912 name_entry_mode_menu[1].flags = (NameEntryMode==1)?D_SELECTED:0;
7913 name_entry_mode_menu[2].flags = (NameEntryMode==2)?D_SELECTED:0;
7914
7915 misc_menu[12].flags =(zasm_debugger)?D_SELECTED:0;
7916 misc_menu[13].flags =(zscript_debugger)?D_SELECTED:0;
7917 misc_menu[14].flags =(clearConsoleOnLoad)?D_SELECTED:0;
7918
7919 bool nocheat = (replay_is_replaying() || !Playing
7920 || (!zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7921 the_player_menu[2].flags = nocheat ? D_DISABLED : 0;
7922 cheat_menu[0].flags = 0;
7923 refill_menu[4].flags = get_qr(qr_TRUEARROWS) ? 0 : D_DISABLED;
7924 cheat_menu[1].text = (cheat >= 1) || get_debug() ? bar_str : NULL;
7925 cheat_menu[3].text = (cheat >= 2) || get_debug() ? bar_str : NULL;
7926 cheat_menu[8].text = (cheat >= 3) || get_debug() ? bar_str : NULL;
7927 cheat_menu[10].text = (cheat >= 4) || get_debug() ? bar_str : NULL;
7928 cheat_menu[4].flags = getClock() ? D_SELECTED : 0;
7929 cheat_menu[11].flags = toogam ? D_SELECTED : 0;
7930 cheat_menu[12].flags = ignoreSideview ? D_SELECTED : 0;
7931 cheat_menu[13].flags = gofast ? D_SELECTED : 0;
7932
7933 show_menu[0].flags = show_layer_0 ? D_SELECTED : 0;
7934 show_menu[1].flags = show_layer_1 ? D_SELECTED : 0;
7935 show_menu[2].flags = show_layer_2 ? D_SELECTED : 0;
7936 show_menu[3].flags = show_layer_3 ? D_SELECTED : 0;
7937 show_menu[4].flags = show_layer_4 ? D_SELECTED : 0;
7938 show_menu[5].flags = show_layer_5 ? D_SELECTED : 0;
7939 show_menu[6].flags = show_layer_6 ? D_SELECTED : 0;
7940 show_menu[7].flags = show_layer_over ? D_SELECTED : 0;
7941 show_menu[8].flags = show_layer_push ? D_SELECTED : 0;
7942 show_menu[9].flags = show_sprites ? D_SELECTED : 0;
7943 show_menu[10].flags = show_ffcs ? D_SELECTED : 0;
7944 show_menu[12].flags = show_walkflags ? D_SELECTED : 0;
7945 show_menu[13].flags = show_ff_scripts ? D_SELECTED : 0;
7946 show_menu[14].flags = show_hitboxes ? D_SELECTED : 0;
7947 show_menu[15].flags = show_effectflags ? D_SELECTED : 0;
7948
7949 settings_menu[8].flags = heart_beep ? D_SELECTED : 0;
7950 settings_menu[12].flags = use_save_indicator ? D_SELECTED : 0;
7951
7952 replay_menu[0].text = zc_get_config("zeldadx", "replay_new_saves", false) ?
7953 (char *)"Disable recording new saves" :
7954 (char *)"Enable recording new saves";
7955 replay_menu[1].flags = replay_is_active() ? 0 : D_DISABLED;
7956 replay_menu[1].text = replay_get_mode() == ReplayMode::Record ?
7957 (char *)"Stop recording" :
7958 (char *)"Stop replaying";
7959 replay_menu[5].flags = replay_get_mode() == ReplayMode::Record ? 0 : D_DISABLED;
7960 replay_menu[6].text = replay_is_snapshot_all_frames() ?
7961 (char *)"Disable snapshot all frames" :
7962 (char *)"Enable snapshot all frames";
7963
7964 reset_snapshot_format_menu();
7965 snapshot_format_menu[SnapshotFormat].flags = D_SELECTED;
7966
7967 if(debug_enabled)
7968 {
7969 settings_menu[14].flags = get_debug() ? D_SELECTED : 0;
7970 }
7971
7972 if(gui_mouse_b() && !mouse_down)
7973 break;
7974
7975 // press menu to drop the menu
7976 if(rMbtn())
7977 simulate_keypress(KEY_G << 8);
7978
7979 if(input_idle(true) > after_time())
7980 // run Screeen Saver
7981 {
7982 // Screen saver enabled for now.
7983 clear_keybuf();
7984 Matrix(ss_speed, ss_density, 0);
7985 system_pal(true);
7986 sys_mouse();
7987 broadcast_dialog_message(MSG_DRAW, 0);
7988 }
7989
7990 update_hw_screen();
7991 }
7992 while(update_dialog(p));
7993
7994 screen = oldscreen;
7995
7996 // font=oldfont;
7997 mouse_down=gui_mouse_b();
7998 shutdown_dialog(p);
7999 MenuOpen = false;
8000 if(Quit)
8001 {
8002 kill_sfx();
8003 music_stop();
8004 update_hw_screen();
8005 }
8006 else
8007 {
8008 music_resume();
8009 resume_all_sfx();
8010
8011 if(rc)
8012 ringcolor(false);
8013 }
8014 exit_sys_pal();
8015
8016 eat_buttons();
8017
8018 rc=false;
8019 clear_keybuf();
8020
8021 zc_init_apply_cheat_delta();
8022 }
8023
8024 115 void fix_dialogs()
8025 {
8026 115 jwin_center_dialog(about_dlg);
8027 115 jwin_center_dialog(gamepad_dlg);
8028 115 jwin_center_dialog(credits_dlg);
8029 115 jwin_center_dialog(gamemode_dlg);
8030 115 jwin_center_dialog(getnum_dlg);
8031 115 jwin_center_dialog(goto_dlg);
8032 115 jwin_center_dialog(keyboard_control_dlg);
8033 115 jwin_center_dialog(midi_dlg);
8034 115 jwin_center_dialog(quest_dlg);
8035 115 jwin_center_dialog(scrsaver_dlg);
8036 115 jwin_center_dialog(sound_dlg);
8037 115 jwin_center_dialog(triforce_dlg);
8038
8039 // digi_dp[1] += scrx;
8040 // digi_dp[2] += scry;
8041 // midi_dp[1] += scrx;
8042 // midi_dp[2] += scry;
8043 // pan_dp[1] += scrx;
8044 // pan_dp[2] += scry;
8045 // emus_dp[1] += scrx;
8046 // emus_dp[2] += scry;
8047 // buf_dp[1] += scrx;
8048 // buf_dp[2] += scry;
8049 // sfx_dp[1] += scrx;
8050 // sfx_dp[2] += scry;
8051 115 }
8052
8053 /*****************************/
8054 /**** Custom Sound System ****/
8055 /*****************************/
8056
8057 115 INLINE int32_t mixvol(int32_t v1,int32_t v2)
8058 {
8059
2/4
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
115 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
8060 }
8061
8062 // Run an NSF, or a MIDI if the NSF is missing somehow.
8063 149 bool try_zcmusic(const char *filename, int32_t track, int32_t midi, int32_t fadeoutframes)
8064 {
8065 149 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8066
8067 // Found it
8068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if(newzcmusic!=NULL)
8069 {
8070 newzcmusic->fadevolume = 10000;
8071 newzcmusic->fadeoutframes = fadeoutframes;
8072
8073 zcmixer->newtrack = newzcmusic;
8074
8075 zcmusic_stop(zcmusic);
8076 zcmusic_unload_file(zcmusic);
8077 zc_stop_midi();
8078
8079 zcmusic=newzcmusic;
8080 int32_t temp_volume = emusic_volume;
8081 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8082 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
8083 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
8084 zcmusic_play(zcmusic, temp_volume);
8085
8086 if(track>0)
8087 zcmusic_change_track(zcmusic,track);
8088
8089 return true;
8090 }
8091
8092 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8093
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 70 times.
149 else if(midi>-1000)
8094 70 jukebox(midi);
8095
8096 149 return false;
8097 149 }
8098
8099 bool try_zcmusic_ex(char *filename, int32_t track, int32_t midi)
8100 {
8101 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8102 // Found it
8103 if(newzcmusic!=NULL)
8104 {
8105 zcmusic_stop(zcmusic);
8106 zcmusic_unload_file(zcmusic);
8107 zc_stop_midi();
8108
8109 zcmusic=newzcmusic;
8110 zcmusic_play(zcmusic, emusic_volume);
8111
8112 if(track>0)
8113 zcmusic_change_track(zcmusic,track);
8114
8115 return true;
8116 }
8117
8118 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8119 else if(midi>-1000)
8120 jukebox(midi);
8121
8122 return false;
8123 }
8124
8125 int32_t get_zcmusicpos()
8126 {
8127 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
8128 return debugtracething;
8129 return 0;
8130 }
8131
8132 void set_zcmusicpos(int32_t position)
8133 {
8134 zcmusic_set_curpos(zcmusic, position);
8135 }
8136
8137 void set_zcmusicspeed(int32_t speed)
8138 {
8139 zcmusic_set_speed(zcmusic, speed);
8140 }
8141
8142 int32_t get_zcmusiclen()
8143 {
8144 return zcmusic_get_length(zcmusic);
8145 }
8146
8147 void set_zcmusicloop(double start, double end)
8148 {
8149 zcmusic_set_loop(zcmusic, start, end);
8150 }
8151
8152 63941 void jukebox(int32_t index,int32_t loop)
8153 {
8154
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if (is_headless())
8155 63941 return;
8156
8157 music_stop();
8158
8159 if(index<0) index=MAXMIDIS-1;
8160
8161 if(index>=MAXMIDIS) index=0;
8162
8163 music_stop();
8164
8165 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8166 // stuck notes when a song stops. This fixes it.
8167 if(strcmp(midi_driver->name, "DIGMID")==0)
8168 zc_set_volume(0, 0);
8169
8170 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8171 zc_play_midi((MIDI*)tunes[index].data,loop);
8172
8173 if(tunes[index].start>0)
8174 zc_midi_seek(tunes[index].start);
8175
8176 midi_loop_start = tunes[index].loop_start;
8177 midi_loop_end = tunes[index].loop_end;
8178
8179 currmidi=index;
8180 master_volume(digi_volume, midi_volume);
8181 //midi_paused=false;
8182 63941 }
8183
8184 63941 void jukebox(int32_t index)
8185 {
8186
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index<0) index=MAXMIDIS-1;
8187
8188
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index>=MAXMIDIS) index=0;
8189
8190 // do nothing if it's already playing
8191
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 63941 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
63941 if(index==currmidi && midi_pos>=0)
8192 {
8193 return;
8194 }
8195
8196 63941 jukebox(index,tunes[index].loop);
8197 63941 }
8198
8199 16 void play_DmapMusic()
8200 {
8201
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (is_headless())
8202 16 return;
8203
8204 static char tfile[2048];
8205 static int32_t ttrack=0;
8206 bool domidi=false;
8207
8208 int32_t fadeoutframes = 0;
8209 if (zcmusic != NULL)
8210 fadeoutframes = zcmusic->fadeoutframes;
8211
8212 if(DMaps[currdmap].tmusic[0]!=0)
8213 {
8214 if(zcmusic==NULL ||
8215 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
8216 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
8217 {
8218 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8219 {
8220 if (FFCore.play_enh_music_crossfade(DMaps[currdmap].tmusic, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
8221 {
8222 if (zcmusic != NULL)
8223 {
8224 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
8225 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8226 }
8227 }
8228 }
8229 else
8230 {
8231 if (zcmusic != NULL)
8232 {
8233 zcmusic_stop(zcmusic);
8234 zcmusic_unload_file(zcmusic);
8235 zcmusic = NULL;
8236 zcmixer->newtrack = NULL;
8237 }
8238
8239 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
8240 zcmixer->newtrack = zcmusic;
8241
8242 if (zcmusic != NULL)
8243 {
8244 zc_stop_midi();
8245 strcpy(tfile, DMaps[currdmap].tmusic);
8246 zcmusic_play(zcmusic, emusic_volume);
8247 int32_t temptracks = 0;
8248 temptracks = zcmusic_get_tracks(zcmusic);
8249 temptracks = (temptracks < 2) ? 1 : temptracks;
8250 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8251 zcmusic_change_track(zcmusic, ttrack);
8252 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8253 }
8254 else
8255 {
8256 tfile[0] = 0;
8257 domidi = true;
8258 }
8259 }
8260 }
8261 }
8262 else
8263 {
8264 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8265 {
8266 FFCore.play_enh_music_crossfade(NULL, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8267 }
8268 else
8269 {
8270 domidi = true;
8271 }
8272 }
8273
8274 if(domidi)
8275 {
8276 int32_t m=DMaps[currdmap].midi;
8277
8278 switch(m)
8279 {
8280 case 1:
8281 jukebox(ZC_MIDI_OVERWORLD);
8282 break;
8283
8284 case 2:
8285 jukebox(ZC_MIDI_DUNGEON);
8286 break;
8287
8288 case 3:
8289 jukebox(ZC_MIDI_LEVEL9);
8290 break;
8291
8292 default:
8293 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8294 jukebox(m+MIDIOFFSET_DMAP);
8295 else
8296 music_stop();
8297 }
8298 }
8299 16 }
8300
8301 15753 void playLevelMusic()
8302 {
8303
1/2
✓ Branch 0 taken 15753 times.
✗ Branch 1 not taken.
15753 if (is_headless())
8304 15753 return;
8305
8306 int32_t m=tmpscr->screen_midi;
8307
8308 switch(m)
8309 {
8310 case -2:
8311 music_stop();
8312 break;
8313
8314 case -1:
8315 play_DmapMusic();
8316 break;
8317
8318 case 1:
8319 jukebox(ZC_MIDI_OVERWORLD);
8320 break;
8321
8322 case 2:
8323 jukebox(ZC_MIDI_DUNGEON);
8324 break;
8325
8326 case 3:
8327 jukebox(ZC_MIDI_LEVEL9);
8328 break;
8329
8330 default:
8331 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8332 jukebox(m+MIDIOFFSET_MAPSCR);
8333 else
8334 music_stop();
8335 }
8336 15753 }
8337
8338 115 void master_volume(int32_t dv,int32_t mv)
8339 {
8340
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✗ Branch 7 not taken.
115 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8341
8342
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✗ Branch 7 not taken.
115 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8343
8344
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✓ Branch 2 taken 115 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 115 times.
115 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8345 115 int32_t temp_vol = midi_volume;
8346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8347 115 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8348 115 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8349 115 }
8350
8351 /*****************/
8352 /***** SFX *****/
8353 /*****************/
8354
8355 // array of voices, one for each sfx sample in the data file
8356 // 0+ = voice #
8357 // -1 = voice not allocated
8358 115 void Z_init_sound()
8359 {
8360
2/2
✓ Branch 0 taken 29440 times.
✓ Branch 1 taken 115 times.
29555 for(int32_t i=0; i<WAV_COUNT; i++)
8361 29440 sfx_voice[i]=-1;
8362
8363 115 const char* midis[ZC_MIDI_COUNT] = {
8364 "assets/dungeon.mid",
8365 "assets/ending.mid",
8366 "assets/gameover.mid",
8367 "assets/level9.mid",
8368 "assets/overworld.mid",
8369 "assets/title.mid",
8370 "assets/triforce.mid",
8371 };
8372
2/2
✓ Branch 0 taken 805 times.
✓ Branch 1 taken 115 times.
920 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8373 {
8374 805 tunes[i].data = load_midi(midis[i]);
8375
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 if (!tunes[i].data)
8376 Z_error_fatal("Missing required file %s\n", midis[i]);
8377 805 }
8378
8379
2/2
✓ Branch 0 taken 28980 times.
✓ Branch 1 taken 115 times.
29095 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8380 28980 tunes[ZC_MIDI_COUNT+j].data=NULL;
8381
8382 115 master_volume(digi_volume,midi_volume);
8383 115 }
8384
8385 // returns number of voices currently allocated
8386 int32_t sfx_count()
8387 {
8388 int32_t c=0;
8389
8390 for(int32_t i=0; i<WAV_COUNT; i++)
8391 if(sfx_voice[i]!=-1)
8392 ++c;
8393
8394 return c;
8395 }
8396
8397 // clean up finished samples
8398 9217346 void sfx_cleanup()
8399 {
8400
2/2
✓ Branch 0 taken 2359640576 times.
✓ Branch 1 taken 9217346 times.
2368857922 for(int32_t i=0; i<WAV_COUNT; i++)
8401
3/4
✓ Branch 0 taken 619381 times.
✓ Branch 1 taken 2359021195 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 619381 times.
2360259957 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8402 {
8403 619381 deallocate_voice(sfx_voice[i]);
8404 619381 sfx_voice[i]=-1;
8405 619381 }
8406 9217346 }
8407
8408 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8409 // if a voice is already allocated (and/or playing), then it just returns true
8410 // Returns true: voice is allocated
8411 // false: unsuccessful
8412 963799 bool sfx_init(int32_t index)
8413 {
8414 // check index
8415
3/4
✓ Branch 0 taken 721410 times.
✓ Branch 1 taken 242389 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721410 times.
963799 if(index<=0 || index>=WAV_COUNT)
8416 242389 return false;
8417
8418
2/2
✓ Branch 0 taken 102011 times.
✓ Branch 1 taken 619399 times.
721410 if(sfx_voice[index]==-1)
8419 {
8420
2/2
✓ Branch 0 taken 209876 times.
✓ Branch 1 taken 409523 times.
619399 if(sfxdat)
8421 {
8422
1/2
✓ Branch 0 taken 209876 times.
✗ Branch 1 not taken.
209876 if(index<Z35)
8423 {
8424 209876 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[index].dat);
8425 209876 }
8426 else
8427 {
8428 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[Z35].dat);
8429 }
8430 209876 }
8431 else
8432 {
8433 409523 sfx_voice[index]=allocate_voice(&customsfxdata[index]);
8434 }
8435
8436 619399 int32_t temp_volume = sfx_volume;
8437
2/4
✓ Branch 0 taken 619399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 619399 times.
✗ Branch 3 not taken.
619399 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8438 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8439 619399 voice_set_volume(sfx_voice[index], temp_volume);
8440 619399 }
8441
8442 721410 return sfx_voice[index] != -1;
8443 963799 }
8444
8445 int32_t sfx_get_default_freq(int32_t index)
8446 {
8447 if (sfxdat)
8448 {
8449 if (index < Z35)
8450 {
8451 return ((SAMPLE*)sfxdata[index].dat)->freq;
8452 }
8453 else
8454 {
8455 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8456 }
8457 }
8458 else
8459 {
8460 return customsfxdata[index].freq;
8461 }
8462 }
8463
8464 int32_t sfx_get_length(int32_t index)
8465 {
8466 if (sfxdat)
8467 {
8468 if (index < Z35)
8469 {
8470 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8471 }
8472 else
8473 {
8474 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8475 }
8476 }
8477 else
8478 {
8479 return int32_t(customsfxdata[index].len);
8480 }
8481 }
8482
8483 // plays an sfx sample
8484 963799 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8485 {
8486
2/2
✓ Branch 0 taken 721410 times.
✓ Branch 1 taken 242389 times.
963799 if(!sfx_init(index))
8487 242389 return;
8488
1/2
✓ Branch 0 taken 721410 times.
✗ Branch 1 not taken.
721410 if (!is_headless())
8489 {
8490 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8491 voice_set_pan(sfx_voice[index], pan);
8492
8493 // Only used by ZScript currently
8494 if (freq <= -1)
8495 {
8496 freq = sfx_get_default_freq(index);
8497 }
8498 voice_set_frequency(sfx_voice[index], freq);
8499
8500 // Only used by ZScript currently
8501 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8502 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8503 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8504 voice_set_volume(sfx_voice[index], temp_volume);
8505
8506 int32_t pos = voice_get_position(sfx_voice[index]);
8507
8508 if (restart) voice_set_position(sfx_voice[index], 0);
8509
8510 if (pos <= 0)
8511 voice_start(sfx_voice[index]);
8512 }
8513
8514
3/4
✓ Branch 0 taken 397878 times.
✓ Branch 1 taken 323532 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 397878 times.
721410 if (restart && replay_is_debug())
8515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397878 times.
397878 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8516 963799 }
8517
8518 // true if sfx is allocated
8519 68051 bool sfx_allocated(int32_t index)
8520 {
8521
3/4
✓ Branch 0 taken 9922 times.
✓ Branch 1 taken 58129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9922 times.
68051 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8522 }
8523
8524 // start it (in loop mode) if it's not already playing,
8525 // otherwise adjust it to play in loop mode -DD
8526 55172 void cont_sfx(int32_t index)
8527 {
8528
1/2
✓ Branch 0 taken 55172 times.
✗ Branch 1 not taken.
55172 if (is_headless())
8529 55172 return;
8530
8531 if(!sfx_init(index))
8532 {
8533 return;
8534 }
8535
8536 if(voice_get_position(sfx_voice[index])<=0)
8537 {
8538 voice_set_position(sfx_voice[index],0);
8539 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8540 voice_start(sfx_voice[index]);
8541 }
8542 else
8543 {
8544 adjust_sfx(index, 128, true);
8545 }
8546 55172 }
8547
8548 // adjust parameters while playing
8549 4075 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8550 {
8551
4/6
✓ Branch 0 taken 2315 times.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 2315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2315 times.
4075 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8552 4075 return;
8553
8554 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8555 voice_set_pan(sfx_voice[index],pan);
8556 4075 }
8557
8558 // pauses a voice
8559 1725 void pause_sfx(int32_t index)
8560 {
8561
3/6
✓ Branch 0 taken 1725 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1725 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1725 times.
1725 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8562 voice_stop(sfx_voice[index]);
8563 1725 }
8564
8565 // resumes a voice
8566 747 void resume_sfx(int32_t index)
8567 {
8568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
747 if (is_headless())
8569 747 return;
8570
8571 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8572 voice_start(sfx_voice[index]);
8573 747 }
8574
8575 // pauses all active voices
8576 448 void pause_all_sfx()
8577 {
8578
2/2
✓ Branch 0 taken 114688 times.
✓ Branch 1 taken 448 times.
115136 for(int32_t i=0; i<WAV_COUNT; i++)
8579
2/2
✓ Branch 0 taken 114687 times.
✓ Branch 1 taken 1 times.
114689 if(sfx_voice[i]!=-1)
8580 1 voice_stop(sfx_voice[i]);
8581 448 }
8582
8583 // resumes all paused voices
8584 434 void resume_all_sfx()
8585 {
8586
2/2
✓ Branch 0 taken 111104 times.
✓ Branch 1 taken 434 times.
111538 for(int32_t i=0; i<WAV_COUNT; i++)
8587
1/2
✓ Branch 0 taken 111104 times.
✗ Branch 1 not taken.
111104 if(sfx_voice[i]!=-1)
8588 voice_start(sfx_voice[i]);
8589 434 }
8590
8591 // stops an sfx and deallocates the voice
8592 7462080 void stop_sfx(int32_t index)
8593 {
8594
3/4
✓ Branch 0 taken 6277014 times.
✓ Branch 1 taken 1185066 times.
✓ Branch 2 taken 6277014 times.
✗ Branch 3 not taken.
7462080 if(index<=0 || index>=WAV_COUNT)
8595 1185066 return;
8596
8597
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6277002 times.
6277014 if(sfx_voice[index]!=-1)
8598 {
8599 12 deallocate_voice(sfx_voice[index]);
8600 12 sfx_voice[index]=-1;
8601 12 }
8602 7462080 }
8603
8604 // Stops SFX played by Hero's item of the given family
8605 128638 void stop_item_sfx(int32_t family)
8606 {
8607 128638 int32_t id=current_item_id(family);
8608
8609
2/2
✓ Branch 0 taken 128083 times.
✓ Branch 1 taken 555 times.
128638 if(id<0)
8610 128083 return;
8611
8612 555 stop_sfx(itemsbuf[id].usesound);
8613 128638 }
8614
8615 3221 void kill_sfx()
8616 {
8617
2/2
✓ Branch 0 taken 824576 times.
✓ Branch 1 taken 3221 times.
827797 for(int32_t i=0; i<WAV_COUNT; i++)
8618
2/2
✓ Branch 0 taken 824570 times.
✓ Branch 1 taken 6 times.
824582 if(sfx_voice[i]!=-1)
8619 {
8620 6 deallocate_voice(sfx_voice[i]);
8621 6 sfx_voice[i]=-1;
8622 6 }
8623 3221 }
8624
8625 659526 int32_t pan(int32_t x)
8626 {
8627
1/4
✓ Branch 0 taken 659526 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
659526 switch(pan_style)
8628 {
8629 case 0:
8630 return 128;
8631
8632 case 1:
8633 659526 return vbound((x>>1)+68,0,255);
8634
8635 case 2:
8636 return vbound(((x*3)>>2)+36,0,255);
8637 }
8638
8639 return vbound(x,0,255);
8640 659526 }
8641
8642 /*******************************/
8643 /******* Input Handlers ********/
8644 /*******************************/
8645
8646 25090768 bool joybtn(int32_t b)
8647 {
8648
1/2
✓ Branch 0 taken 25090768 times.
✗ Branch 1 not taken.
25090768 if(b == 0)
8649 return false;
8650
1/2
✓ Branch 0 taken 25090768 times.
✗ Branch 1 not taken.
25090768 if (b-1 >= joy[joystick_index].num_buttons)
8651 25090768 return false;
8652
8653 return joy[joystick_index].button[b-1].b !=0;
8654 25090768 }
8655
8656 bool joystick(int32_t s)
8657 {
8658 if(s < 0)
8659 return false;
8660 if (s >= joy[joystick_index].num_sticks)
8661 return false;
8662
8663 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8664 {
8665 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8666 return true;
8667 }
8668 return false;
8669 }
8670
8671 const char* joybtn_name(int32_t b)
8672 {
8673 if (b <= 0 || b > joy[joystick_index].num_buttons)
8674 return "";
8675
8676 return joy[joystick_index].button[b-1].name;
8677 }
8678
8679 const char* joystick_name(int32_t s)
8680 {
8681 if (s < 0 || s >= joy[joystick_index].num_sticks)
8682 return "";
8683
8684 return joy[joystick_index].stick[s].name;
8685 }
8686
8687 int32_t next_press_key();
8688
8689 int32_t next_joy_input(bool buttons)
8690 {
8691 clear_keybuf();
8692
8693 //first, we need to wait until they're pressing no buttons
8694 for(;;)
8695 {
8696 if(keypressed())
8697 {
8698 switch(readkey()>>8)
8699 {
8700 case KEY_ESC:
8701 return -1;
8702
8703 case KEY_SPACE:
8704 return 0;
8705 }
8706 }
8707
8708 poll_joystick();
8709 bool done = true;
8710
8711 if (buttons)
8712 {
8713 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8714 {
8715 if(joybtn(i)) done = false;
8716 }
8717 }
8718 else
8719 {
8720 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8721 {
8722 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8723 return -2;
8724 }
8725 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8726 {
8727 if(joystick(i)) done = false;
8728 }
8729 }
8730
8731 if(done) break;
8732 rest(1);
8733 }
8734
8735 //now, we need to wait for them to press any button
8736 for(;;)
8737 {
8738 if(keypressed())
8739 {
8740 switch(readkey()>>8)
8741 {
8742 case KEY_ESC:
8743 return -1;
8744
8745 case KEY_SPACE:
8746 return 0;
8747 }
8748 }
8749
8750 poll_joystick();
8751
8752 if (buttons)
8753 {
8754 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8755 {
8756 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8757 return -2;
8758 }
8759 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8760 {
8761 if(joybtn(i))
8762 return i;
8763 }
8764 }
8765 else
8766 {
8767 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8768 {
8769 if(joystick(i))
8770 return i;
8771 }
8772 }
8773 rest(1);
8774 }
8775 }
8776
8777 1208942 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8778 {
8779
2/2
✓ Branch 0 taken 1204591 times.
✓ Branch 1 taken 4351 times.
1208942 bool ret = btn && !flag;
8780 1208942 flag = rawbtn;
8781
8782 1208942 return ret;
8783 }
8784 190783574 static bool rButton(bool &btn, bool &flag)
8785 {
8786
2/2
✓ Branch 0 taken 183940445 times.
✓ Branch 1 taken 6843129 times.
190783574 bool ret = btn && !flag;
8787 190783574 flag = btn;
8788
8789 190783574 return ret;
8790 }
8791 2888422 static bool rButtonPeek(bool btn, bool flag)
8792 {
8793
2/2
✓ Branch 0 taken 2685421 times.
✓ Branch 1 taken 203001 times.
2888422 if(!btn)
8794 {
8795 2685421 return false;
8796 }
8797
2/2
✓ Branch 0 taken 17917 times.
✓ Branch 1 taken 185084 times.
203001 else if(!flag)
8798 {
8799 17917 return true;
8800 }
8801
8802 185084 return false;
8803 2888422 }
8804
8805 // Updated only by keyboard/gamepad.
8806 // If in replay mode, this is set directly by the replay system.
8807 // This should never be read from directly - use control_state instead.
8808 bool raw_control_state[ZC_CONTROL_STATES];
8809
8810 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8811 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8812 // lasts until the next call to load_control_state.
8813 bool control_state[ZC_CONTROL_STATES];
8814 bool disable_control[ZC_CONTROL_STATES];
8815 bool drunk_toggle_state[11];
8816 bool disabledKeys[127];
8817 bool KeyInput[127];
8818 bool KeyPress[127];
8819
8820 bool key_current_frame[127];
8821 bool key_previous_frame[127];
8822
8823 static bool key_system[127];
8824 static bool key_system_previous[127];
8825 static bool key_system_press[127];
8826
8827 bool button_press[ZC_CONTROL_STATES];
8828 bool button_hold[ZC_CONTROL_STATES];
8829
8830 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8831 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8832 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8833 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8834 #define STICK_PRECISION 56 //define your own sensitivity
8835
8836 7800183 void load_control_state()
8837 {
8838 7800183 load_control_called_this_frame = true;
8839
8840
2/2
✓ Branch 0 taken 4833663 times.
✓ Branch 1 taken 2966520 times.
7800183 if (replay_version_check(8, 11))
8841 {
8842
2/2
✓ Branch 0 taken 53397360 times.
✓ Branch 1 taken 2966520 times.
56363880 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8843 53397360 down_control_states[i] = raw_control_state[i];
8844 2966520 }
8845
8846
1/2
✓ Branch 0 taken 7800183 times.
✗ Branch 1 not taken.
7800183 if (!replay_is_replaying())
8847 {
8848 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8849 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8850 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8851 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8852 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8853 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8854 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8855 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8856 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8857 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8858 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8859 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8860 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8861 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8862
8863 if(num_joysticks != 0)
8864 {
8865 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8866 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8867 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8868 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8869 // zprint2("Detected %d joysticks... %d%d%d%d\n", num_joysticks, raw_control_state[14]?1:0, raw_control_state[15]?1:0, raw_control_state[16]?1:0, raw_control_state[17]?1:0);
8870 }
8871 else
8872 {
8873 raw_control_state[14] = false;
8874 raw_control_state[15] = false;
8875 raw_control_state[16] = false;
8876 raw_control_state[17] = false;
8877 // zprint2("Detected 0 joysticks... clearing inputaxis values.\n");
8878 }
8879 }
8880
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7800180 times.
7800183 if (replay_is_active())
8881 {
8882
2/2
✓ Branch 0 taken 1015215 times.
✓ Branch 1 taken 6784965 times.
7800180 if (replay_get_version() < 3)
8883 1015215 replay_poll();
8884
3/4
✓ Branch 0 taken 6784965 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5023590 times.
✓ Branch 3 taken 1761375 times.
6784965 else if (replay_is_replaying() && replay_get_version() < 6)
8885 1761375 replay_peek_input();
8886
3/4
✓ Branch 0 taken 5023590 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2057070 times.
✓ Branch 3 taken 2966520 times.
5023590 else if (replay_is_replaying() && replay_version_check(8, 11))
8887 2966520 replay_peek_input();
8888
2/2
✓ Branch 0 taken 6696883 times.
✓ Branch 1 taken 1103297 times.
7800180 if (replay_get_version() == 8)
8889 1103297 update_keys();
8890 7800180 }
8891
8892 // Some test replay files were made before a serious input bug was fixed, so instead
8893 // of re-doing them or tossing them out, just check for that zplay version.
8894
3/4
✓ Branch 0 taken 7800177 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 7678277 times.
7800183 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8895
2/2
✓ Branch 0 taken 140403186 times.
✓ Branch 1 taken 7800177 times.
148203363 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8896 {
8897 140403186 control_state[i] = raw_control_state[i];
8898
4/4
✓ Branch 0 taken 49487310 times.
✓ Branch 1 taken 90915876 times.
✓ Branch 2 taken 2410168 times.
✓ Branch 3 taken 47077142 times.
140403186 if (botched_input && !control_state[i])
8899 47077142 down_control_states[i] = false;
8900 140403186 }
8901 7800177 bool did_bad_cutscene_btn = false;
8902
2/2
✓ Branch 0 taken 7800177 times.
✓ Branch 1 taken 140403186 times.
148203363 for(int q = 0; q < 18; ++q)
8903
4/4
✓ Branch 0 taken 6463821 times.
✓ Branch 1 taken 133939365 times.
✓ Branch 2 taken 6463087 times.
✓ Branch 3 taken 734 times.
140403920 if(control_state[q] && !active_cutscene.can_button(q))
8904 {
8905 734 control_state[q] = false;
8906 734 did_bad_cutscene_btn = true;
8907 734 }
8908
2/2
✓ Branch 0 taken 7799662 times.
✓ Branch 1 taken 515 times.
7800177 if(did_bad_cutscene_btn)
8909 515 active_cutscene.error();
8910
8911 7800177 button_press[0]=rButton(control_state[0],button_hold[0]);
8912 7800177 button_press[1]=rButton(control_state[1],button_hold[1]);
8913 7800177 button_press[2]=rButton(control_state[2],button_hold[2]);
8914 7800177 button_press[3]=rButton(control_state[3],button_hold[3]);
8915 7800177 button_press[4]=rButton(control_state[4],button_hold[4]);
8916 7800177 button_press[5]=rButton(control_state[5],button_hold[5]);
8917 7800177 button_press[6]=rButton(control_state[6],button_hold[6]);
8918 7800177 button_press[7]=rButton(control_state[7],button_hold[7]);
8919 7800177 button_press[8]=rButton(control_state[8],button_hold[8]);
8920 7800177 button_press[9]=rButton(control_state[9],button_hold[9]);
8921 7800177 button_press[10]=rButton(control_state[10],button_hold[10]);
8922 7800177 button_press[11]=rButton(control_state[11],button_hold[11]);
8923 7800177 button_press[12]=rButton(control_state[12],button_hold[12]);
8924 7800177 button_press[13]=rButton(control_state[13],button_hold[13]);
8925 7800177 button_press[14]=rButton(control_state[14],button_hold[14]);
8926 7800177 button_press[15]=rButton(control_state[15],button_hold[15]);
8927 7800177 button_press[16]=rButton(control_state[16],button_hold[16]);
8928 7800177 button_press[17]=rButton(control_state[17],button_hold[17]);
8929 7800177 }
8930
8931 // Returns true if any game key is pressed. This is needed because keypressed()
8932 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8933 40245648 bool zc_key_pressed()
8934 //may also need to use zc_getrawkey
8935 {
8936
7/10
✓ Branch 0 taken 32593641 times.
✓ Branch 1 taken 7652007 times.
✓ Branch 2 taken 7652007 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7652007 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6395615 times.
✓ Branch 7 taken 6395615 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2461435 times.
42707083 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8937
4/6
✓ Branch 0 taken 6395615 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6395615 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4843518 times.
✓ Branch 5 taken 4843518 times.
6395615 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8938
4/6
✓ Branch 0 taken 4843518 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4843518 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3142788 times.
✓ Branch 5 taken 3142788 times.
4843518 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8939
4/6
✓ Branch 0 taken 3142788 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3142788 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2731941 times.
✓ Branch 5 taken 2731941 times.
3142788 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8940
1/2
✓ Branch 0 taken 2731941 times.
✗ Branch 1 not taken.
2731941 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8941
3/4
✓ Branch 0 taken 2612534 times.
✓ Branch 1 taken 119407 times.
✓ Branch 2 taken 2612534 times.
✗ Branch 3 not taken.
2731941 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8942
3/4
✓ Branch 0 taken 2493645 times.
✓ Branch 1 taken 118889 times.
✓ Branch 2 taken 2493645 times.
✗ Branch 3 not taken.
2612534 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8943
3/4
✓ Branch 0 taken 2478500 times.
✓ Branch 1 taken 15145 times.
✓ Branch 2 taken 2478500 times.
✗ Branch 3 not taken.
2493645 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8944
3/4
✓ Branch 0 taken 2465001 times.
✓ Branch 1 taken 13499 times.
✓ Branch 2 taken 2465001 times.
✗ Branch 3 not taken.
2478500 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8945
3/4
✓ Branch 0 taken 2462511 times.
✓ Branch 1 taken 2490 times.
✓ Branch 2 taken 2462511 times.
✗ Branch 3 not taken.
2465001 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8946
3/4
✓ Branch 0 taken 2462293 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 2462293 times.
✗ Branch 3 not taken.
2462511 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8947
3/4
✓ Branch 0 taken 2461454 times.
✓ Branch 1 taken 839 times.
✓ Branch 2 taken 2461454 times.
✗ Branch 3 not taken.
2462293 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8948
2/4
✓ Branch 0 taken 2461454 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461454 times.
✗ Branch 3 not taken.
2461454 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8949
2/2
✓ Branch 0 taken 2461435 times.
✓ Branch 1 taken 19 times.
2461454 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8950 72011937 return true;
8951
8952 2461435 return false;
8953 9286090 }
8954
8955 149943533 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8956 {
8957 149943533 bool ret = false, drunkstate = false, rawret = false;;
8958 149943533 bool* flag = &down_control_states[btn];
8959
2/7
✓ Branch 0 taken 140648106 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 9295427 times.
149943533 switch(btn)
8960 {
8961 case btnF12:
8962 ret = zc_getkey(KEY_F12, ignoreDisable);
8963 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8964 eatEntirely = false;
8965 break;
8966 case btnF11:
8967 ret = zc_getkey(KEY_F11, ignoreDisable);
8968 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8969 eatEntirely = false;
8970 break;
8971 case btnF5:
8972 ret = zc_getkey(KEY_F5, ignoreDisable);
8973 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8974 eatEntirely = false;
8975 break;
8976 case btnQ:
8977 ret = zc_getkey(KEY_Q, ignoreDisable);
8978 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8979 eatEntirely = false;
8980 break;
8981 case btnI:
8982 ret = zc_getkey(KEY_I, ignoreDisable);
8983 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8984 eatEntirely = false;
8985 break;
8986 case btnM:
8987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9295427 times.
9295427 if(FFCore.kb_typing_mode) return false;
8988 9295427 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8989 9295427 eatEntirely = false;
8990 9295427 break;
8991 default: //control_state[] index
8992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140648106 times.
140648106 if(FFCore.kb_typing_mode) return false;
8993
5/6
✓ Branch 0 taken 139848327 times.
✓ Branch 1 taken 799779 times.
✓ Branch 2 taken 2226105 times.
✓ Branch 3 taken 137622222 times.
✓ Branch 4 taken 2226105 times.
✗ Branch 5 not taken.
140648106 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8994
2/2
✓ Branch 0 taken 8034672 times.
✓ Branch 1 taken 132613434 times.
140648106 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8995
4/4
✓ Branch 0 taken 126511720 times.
✓ Branch 1 taken 14136386 times.
✓ Branch 2 taken 3004 times.
✓ Branch 3 taken 14133382 times.
154784492 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8996 140648106 rawret = raw_control_state[btn];
8997 140648106 }
8998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149943533 times.
149943533 assert(flag);
8999
2/2
✓ Branch 0 taken 95465781 times.
✓ Branch 1 taken 54477752 times.
149943533 if(press)
9000 {
9001
2/2
✓ Branch 0 taken 2888422 times.
✓ Branch 1 taken 51589330 times.
54477752 if(peek)
9002 2888422 ret = rButtonPeek(ret, *flag);
9003
2/2
✓ Branch 0 taken 50380388 times.
✓ Branch 1 taken 1208942 times.
51589330 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
9004 1208942 else ret = rButton(ret, *flag, rawret);
9005 54477752 }
9006
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 149943533 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
149943533 if(eatEntirely && ret) control_state[btn] = false;
9007
3/4
✓ Branch 0 taken 112368251 times.
✓ Branch 1 taken 37575282 times.
✓ Branch 2 taken 112368251 times.
✗ Branch 3 not taken.
149943533 if(drunk && drunkstate) ret = !ret;
9008 149943533 return ret;
9009 149943533 }
9010
9011 7464718 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
9012 {
9013 7464718 byte ret = 0;
9014
2/2
✓ Branch 0 taken 5485961 times.
✓ Branch 1 taken 1978757 times.
7464718 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
9015
2/2
✓ Branch 0 taken 7333904 times.
✓ Branch 1 taken 130814 times.
7464718 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
9016
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
9017
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
9018
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
9019
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
9020
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
9021
2/2
✓ Branch 0 taken 7334029 times.
✓ Branch 1 taken 130689 times.
7464718 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
9022 7464718 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
9023 }
9024
9025 1114 byte checkIntBtnVal(byte intbtn, byte vals)
9026 {
9027 1114 return intbtn&vals;
9028 }
9029
9030 1767371 bool Up()
9031 {
9032 1767371 return getInput(btnUp);
9033 }
9034 147199 bool Down()
9035 {
9036 147199 return getInput(btnDown);
9037 }
9038 257607 bool Left()
9039 {
9040 257607 return getInput(btnLeft);
9041 }
9042 286801 bool Right()
9043 {
9044 286801 return getInput(btnRight);
9045 }
9046 164850 bool cAbtn()
9047 {
9048 164850 return getInput(btnA);
9049 }
9050 1411781 bool cBbtn()
9051 {
9052 1411781 return getInput(btnB);
9053 }
9054 bool cSbtn()
9055 {
9056 return getInput(btnS);
9057 }
9058 68744 bool cLbtn()
9059 {
9060 68744 return getInput(btnL);
9061 }
9062 68744 bool cRbtn()
9063 {
9064 68744 return getInput(btnR);
9065 }
9066 bool cPbtn()
9067 {
9068 return getInput(btnP);
9069 }
9070 bool cEx1btn()
9071 {
9072 return getInput(btnEx1);
9073 }
9074 bool cEx2btn()
9075 {
9076 return getInput(btnEx2);
9077 }
9078 bool cEx3btn()
9079 {
9080 return getInput(btnEx3);
9081 }
9082 bool cEx4btn()
9083 {
9084 return getInput(btnEx4);
9085 }
9086 bool AxisUp()
9087 {
9088 return getInput(btnAxisUp);
9089 }
9090 bool AxisDown()
9091 {
9092 return getInput(btnAxisDown);
9093 }
9094 bool AxisLeft()
9095 {
9096 return getInput(btnAxisLeft);
9097 }
9098 bool AxisRight()
9099 {
9100 return getInput(btnAxisRight);
9101 }
9102
9103 bool cMbtn()
9104 {
9105 return getInput(btnM);
9106 }
9107 bool cF12()
9108 {
9109 return getInput(btnF12);
9110 }
9111 bool cF11()
9112 {
9113 return getInput(btnF11);
9114 }
9115 bool cF5()
9116 {
9117 return getInput(btnF5);
9118 }
9119 bool cQ()
9120 {
9121 return getInput(btnQ);
9122 }
9123 bool cI()
9124 {
9125 return getInput(btnI);
9126 }
9127
9128 130270 bool rUp()
9129 {
9130 130270 return getInput(btnUp, true);
9131 }
9132 130174 bool rDown()
9133 {
9134 130174 return getInput(btnDown, true);
9135 }
9136 130122 bool rLeft()
9137 {
9138 130122 return getInput(btnLeft, true);
9139 }
9140 129657 bool rRight()
9141 {
9142 129657 return getInput(btnRight, true);
9143 }
9144 1295 bool rAbtn()
9145 {
9146 1295 return getInput(btnA, true);
9147 }
9148 1295 bool rBbtn()
9149 {
9150 1295 return getInput(btnB, true);
9151 }
9152 7396532 bool rSbtn()
9153 {
9154 7396532 return getInput(btnS, true);
9155 }
9156 9286090 bool rMbtn()
9157 {
9158 9286090 return getInput(btnM, true);
9159 }
9160 129441 bool rLbtn()
9161 {
9162 129441 return getInput(btnL, true);
9163 }
9164 129436 bool rRbtn()
9165 {
9166 129436 return getInput(btnR, true);
9167 }
9168 7332996 bool rPbtn()
9169 {
9170 7332996 return getInput(btnP, true);
9171 }
9172 bool rEx1btn()
9173 {
9174 return getInput(btnEx1, true);
9175 }
9176 bool rEx2btn()
9177 {
9178 return getInput(btnEx2, true);
9179 }
9180 139523 bool rEx3btn()
9181 {
9182 139523 return getInput(btnEx3, true);
9183 }
9184 139523 bool rEx4btn()
9185 {
9186 139523 return getInput(btnEx4, true);
9187 }
9188 bool rAxisUp()
9189 {
9190 return getInput(btnAxisUp, true);
9191 }
9192 bool rAxisDown()
9193 {
9194 return getInput(btnAxisDown, true);
9195 }
9196 bool rAxisLeft()
9197 {
9198 return getInput(btnAxisLeft, true);
9199 }
9200 bool rAxisRight()
9201 {
9202 return getInput(btnAxisRight, true);
9203 }
9204
9205 bool rF11()
9206 {
9207 return getInput(btnF11, true);
9208 }
9209 bool rQ()
9210 {
9211 return getInput(btnQ, true);
9212 }
9213 bool rI()
9214 {
9215 return getInput(btnI, true);
9216 }
9217
9218 18226271 bool DrunkUp()
9219 {
9220 18226271 return getInput(btnUp, false, true);
9221 }
9222 16889226 bool DrunkDown()
9223 {
9224 16889226 return getInput(btnDown, false, true);
9225 }
9226 10288435 bool DrunkLeft()
9227 {
9228 10288435 return getInput(btnLeft, false, true);
9229 }
9230 8834123 bool DrunkRight()
9231 {
9232 8834123 return getInput(btnRight, false, true);
9233 }
9234 8035288 bool DrunkcAbtn()
9235 {
9236 8035288 return getInput(btnA, false, true);
9237 }
9238 8016890 bool DrunkcBbtn()
9239 {
9240 8016890 return getInput(btnB, false, true);
9241 }
9242 7263866 bool DrunkcEx1btn()
9243 {
9244 7263866 return getInput(btnEx1, false, true);
9245 }
9246 7263886 bool DrunkcEx2btn()
9247 {
9248 7263886 return getInput(btnEx2, false, true);
9249 }
9250 bool DrunkcSbtn()
9251 {
9252 return getInput(btnS, false, true);
9253 }
9254 bool DrunkcMbtn()
9255 {
9256 return getInput(btnM, false, true);
9257 }
9258 bool DrunkcLbtn()
9259 {
9260 return getInput(btnL, false, true);
9261 }
9262 bool DrunkcRbtn()
9263 {
9264 return getInput(btnR, false, true);
9265 }
9266 bool DrunkcPbtn()
9267 {
9268 return getInput(btnP, false, true);
9269 }
9270
9271 bool DrunkrUp()
9272 {
9273 return getInput(btnUp, true, true);
9274 }
9275 bool DrunkrDown()
9276 {
9277 return getInput(btnDown, true, true);
9278 }
9279 bool DrunkrLeft()
9280 {
9281 return getInput(btnLeft, true, true);
9282 }
9283 bool DrunkrRight()
9284 {
9285 return getInput(btnRight, true, true);
9286 }
9287 6081738 bool DrunkrAbtn()
9288 {
9289 6081738 return getInput(btnA, true, true);
9290 }
9291 6098559 bool DrunkrBbtn()
9292 {
9293 6098559 return getInput(btnB, true, true);
9294 }
9295 71669 bool DrunkrEx1btn()
9296 {
9297 71669 return getInput(btnEx1, true, true);
9298 }
9299 71662 bool DrunkrEx2btn()
9300 {
9301 71662 return getInput(btnEx2, true, true);
9302 }
9303 bool DrunkrEx3btn()
9304 {
9305 return getInput(btnEx3, true, true);
9306 }
9307 bool DrunkrEx4btn()
9308 {
9309 return getInput(btnEx4, true, true);
9310 }
9311 bool DrunkrSbtn()
9312 {
9313 return getInput(btnS, true, true);
9314 }
9315 bool DrunkrMbtn()
9316 {
9317 return getInput(btnM, true, true);
9318 }
9319 6689212 bool DrunkrLbtn()
9320 {
9321 6689212 return getInput(btnL, true, true);
9322 }
9323 6685737 bool DrunkrRbtn()
9324 {
9325 6685737 return getInput(btnR, true, true);
9326 }
9327 bool DrunkrPbtn()
9328 {
9329 return getInput(btnP, true, true);
9330 }
9331
9332 9337 void eat_buttons()
9333 {
9334 9337 getInput(btnA, true, false, true);
9335 9337 getInput(btnB, true, false, true);
9336 9337 getInput(btnS, true, false, true);
9337 9337 getInput(btnM, true, false, true);
9338 9337 getInput(btnL, true, false, true);
9339 9337 getInput(btnR, true, false, true);
9340 9337 getInput(btnP, true, false, true);
9341 9337 getInput(btnEx1, true, false, true);
9342 9337 getInput(btnEx2, true, false, true);
9343 9337 getInput(btnEx3, true, false, true);
9344 9337 getInput(btnEx4, true, false, true);
9345 9337 }
9346
9347 // Is true for the _first frame_ of a key press.
9348 // But! it is possible that a script manually sets the value of KeyPress,
9349 // in which case it will be restored to the "true" value based on `key_current_frame`
9350 // and `key_previous_frame` on the next frame.
9351 14 bool zc_readkey(int32_t k, bool ignoreDisable)
9352 {
9353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(ignoreDisable) return KeyPress[k];
9354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 switch(k)
9355 {
9356 case KEY_F7:
9357 case KEY_F8:
9358 case KEY_F9:
9359 return KeyPress[k];
9360
9361 default:
9362
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 return KeyPress[k] && !disabledKeys[k];
9363 }
9364 14 }
9365
9366 // Is true for _every frame_ a key is held down.
9367 // But! it is possible that a script manually sets the value of KeyInput,
9368 // in which case it will be restored to the "true" value based on `key_current_frame`
9369 // on the next frame.
9370 bool zc_getkey(int32_t k, bool ignoreDisable)
9371 {
9372 if(ignoreDisable) return KeyInput[k];
9373 switch(k)
9374 {
9375 case KEY_F7:
9376 case KEY_F8:
9377 case KEY_F9:
9378 return KeyInput[k];
9379
9380 default:
9381 return KeyInput[k] && !disabledKeys[k];
9382 }
9383 }
9384
9385 // Reads (and then clears) the current frame key state directly.
9386 // Scripts can also modify `key_current_frame`.
9387 303 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9388 {
9389
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 301 times.
303 if(zc_getrawkey(k, ignoreDisable))
9390 {
9391 2 _key[k]=key[k]=key_current_frame[k]=0;
9392 2 return true;
9393 }
9394 301 _key[k]=key[k]=key_current_frame[k]=0;
9395 301 return false;
9396 303 }
9397
9398 // Reads the current frame key state directly.
9399 // Scripts can also modify `key_current_frame`.
9400 63245081 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9401 {
9402
2/2
✓ Branch 0 taken 53958963 times.
✓ Branch 1 taken 9286118 times.
63245081 if(ignoreDisable) return key_current_frame[k];
9403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286118 times.
9286118 switch(k)
9404 {
9405 case KEY_F7:
9406 case KEY_F8:
9407 case KEY_F9:
9408 return key_current_frame[k];
9409
9410 default:
9411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286118 times.
9286118 return key_current_frame[k] && !disabledKeys[k];
9412 }
9413 63245081 }
9414
9415 // Only used for a handful of keys, like tilde and Function keys.
9416 // This state is never read within the game.
9417 // It exists so that all keyboard input still functions during replay,
9418 // without inadvertently doing things like toggling throttling if the player
9419 // presses ~
9420 9286090 bool zc_get_system_key(int32_t k)
9421 {
9422 9286090 return key_system[k];
9423 }
9424
9425 // True for the _first_ frame of a key press.
9426 83574810 bool zc_read_system_key(int32_t k)
9427 {
9428 83574810 return key_system_press[k];
9429 }
9430
9431 1179333430 bool is_system_key(int32_t k)
9432 {
9433
2/2
✓ Branch 0 taken 1095758620 times.
✓ Branch 1 taken 83574810 times.
1179333430 switch (k)
9434 {
9435 case KEY_BACKQUOTE:
9436 case KEY_CLOSEBRACE:
9437 case KEY_END:
9438 case KEY_HOME:
9439 case KEY_OPENBRACE:
9440 case KEY_PGDN:
9441 case KEY_PGUP:
9442 case KEY_TAB:
9443 case KEY_TILDE:
9444 83574810 return true;
9445 }
9446 1095758620 return is_Fkey(k);
9447 1179333430 }
9448
9449 9286090 void update_system_keys()
9450 {
9451
2/2
✓ Branch 0 taken 1179333430 times.
✓ Branch 1 taken 9286090 times.
1188619520 for (int32_t q = 0; q < 127; ++q)
9452 {
9453
2/2
✓ Branch 0 taken 195007890 times.
✓ Branch 1 taken 984325540 times.
1179333430 if (!is_system_key(q))
9454 984325540 continue;
9455
9456 195007890 key_system[q] = key[q];
9457
1/2
✓ Branch 0 taken 195007890 times.
✗ Branch 1 not taken.
195007890 key_system_press[q] = key_system[q] && !key_system_previous[q];
9458 195007890 key_system_previous[q] = key_system[q];
9459 195007890 }
9460 9286090 }
9461
9462 10389387 void update_keys()
9463 {
9464
2/2
✓ Branch 0 taken 1319452149 times.
✓ Branch 1 taken 10389387 times.
1329841536 for (int32_t q = 0; q < 127; ++q)
9465 {
9466 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9467
1/2
✓ Branch 0 taken 1319452149 times.
✗ Branch 1 not taken.
1319452149 if (!replay_is_replaying())
9468 key_current_frame[q] = key[q];
9469
9470
2/2
✓ Branch 0 taken 1309665979 times.
✓ Branch 1 taken 9786170 times.
1319452149 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9471 1319452149 KeyInput[q] = key_current_frame[q];
9472 1319452149 key_previous_frame[q] = key_current_frame[q];
9473 1319452149 }
9474 10389387 }
9475
9476 bool zc_disablekey(int32_t k, bool val)
9477 {
9478 switch(k)
9479 {
9480 case KEY_F7:
9481 case KEY_F8:
9482 case KEY_F9:
9483 return false;
9484
9485 default:
9486 disabledKeys[k] = val;
9487 return true;
9488 }
9489 }
9490
9491 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9492 {
9493 timer=timer;
9494 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9495 }
9496